Skip to content

Commit 582d240

Browse files
committed
Add the new string attributes to SchemaModelLitteral instead of SchemaModelString
1 parent e4442c0 commit 582d240

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

src/main/kotlin/com/papsign/ktor/openapigen/annotations/type/string/length/LengthConstraintProcessor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class LengthConstraintProcessor<A: Annotation>(): SchemaProcessor<A>, V
1616

1717
val types = listOf(getKType<String>().withNullability(true), getKType<String>().withNullability(false))
1818

19-
abstract fun process(model: SchemaModel.SchemaModelString, annotation: A): SchemaModel.SchemaModelString
19+
abstract fun process(model: SchemaModel.SchemaModelLitteral<*>, annotation: A): SchemaModel.SchemaModelLitteral<*>
2020

2121
abstract fun getConstraint(annotation: A): LengthConstraint
2222

@@ -46,7 +46,7 @@ abstract class LengthConstraintProcessor<A: Annotation>(): SchemaProcessor<A>, V
4646
}
4747

4848
override fun process(model: SchemaModel<*>, type: KType, annotation: A): SchemaModel<*> {
49-
return if (model is SchemaModel.SchemaModelString && types.contains(type)) {
49+
return if (model is SchemaModel.SchemaModelLitteral<*> && types.contains(type)) {
5050
process(model, annotation)
5151
} else {
5252
log.warn("${annotation::class} can only be used on types: $types")

src/main/kotlin/com/papsign/ktor/openapigen/annotations/type/string/length/LengthProcessor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package com.papsign.ktor.openapigen.annotations.type.string.length
33
import com.papsign.ktor.openapigen.model.schema.SchemaModel
44

55
object LengthProcessor : LengthConstraintProcessor<Length>() {
6-
override fun process(model: SchemaModel.SchemaModelString, annotation: Length): SchemaModel.SchemaModelString {
7-
return model.apply {
6+
override fun process(model: SchemaModel.SchemaModelLitteral<*>, annotation: Length): SchemaModel.SchemaModelLitteral<*> {
7+
@Suppress("UNCHECKED_CAST")
8+
return (model as SchemaModel.SchemaModelLitteral<Any?>).apply {
89
maxLength = annotation.max
910
minLength = annotation.min
1011
}

src/main/kotlin/com/papsign/ktor/openapigen/annotations/type/string/length/MaxLengthProcessor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package com.papsign.ktor.openapigen.annotations.type.string.length
33
import com.papsign.ktor.openapigen.model.schema.SchemaModel
44

55
object MaxLengthProcessor : LengthConstraintProcessor<MaxLength>() {
6-
override fun process(model: SchemaModel.SchemaModelString, annotation: MaxLength): SchemaModel.SchemaModelString {
7-
return model.apply {
6+
override fun process(model: SchemaModel.SchemaModelLitteral<*>, annotation: MaxLength): SchemaModel.SchemaModelLitteral<*> {
7+
@Suppress("UNCHECKED_CAST")
8+
return (model as SchemaModel.SchemaModelLitteral<Any?>).apply {
89
maxLength = annotation.value
910
}
1011
}

src/main/kotlin/com/papsign/ktor/openapigen/annotations/type/string/length/MinLengthProcessor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package com.papsign.ktor.openapigen.annotations.type.string.length
33
import com.papsign.ktor.openapigen.model.schema.SchemaModel
44

55
object MinLengthProcessor : LengthConstraintProcessor<MinLength>() {
6-
override fun process(model: SchemaModel.SchemaModelString, annotation: MinLength): SchemaModel.SchemaModelString {
7-
return model.apply {
6+
override fun process(model: SchemaModel.SchemaModelLitteral<*>, annotation: MinLength): SchemaModel.SchemaModelLitteral<*> {
7+
@Suppress("UNCHECKED_CAST")
8+
return (model as SchemaModel.SchemaModelLitteral<Any?>).apply {
89
minLength = annotation.value
910
}
1011
}

src/main/kotlin/com/papsign/ktor/openapigen/model/schema/SchemaModel.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,13 @@ sealed class SchemaModel<T>: DataModel {
5555
var nullable: Boolean = false,
5656
var minimum: T? = null,
5757
var maximum: T? = null,
58-
override var example: T? = null,
59-
override var examples: List<T>? = null,
60-
override var description: String? = null
61-
) : SchemaModel<T>()
62-
63-
data class SchemaModelString(
64-
var type: DataType? = null,
65-
var format: DataFormat? = null,
66-
var nullable: Boolean = false,
6758
var minLength: Int? = null,
6859
var maxLength: Int? = null,
6960
var pattern: String? = null,
70-
override var example: String? = null,
71-
override var examples: List<String>? = null,
61+
override var example: T? = null,
62+
override var examples: List<T>? = null,
7263
override var description: String? = null
73-
) : SchemaModel<String>()
64+
) : SchemaModel<T>()
7465

7566
data class SchemaModelRef<T>(override val `$ref`: String) : SchemaModel<T>(), RefModel<SchemaModel<T>> {
7667
override var example: T? = null

0 commit comments

Comments
 (0)