fix: Support Maps with sealed class type (#211)
This commit is contained in:

committed by
GitHub

parent
89ac0e19dd
commit
1d8e1bc60d
@ -1,6 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
- Fix to support sealed class typed Maps
|
||||
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
|
@ -28,8 +28,7 @@ object MapHandler : SchemaHandler {
|
||||
if (keyType?.classifier != String::class) {
|
||||
error("Invalid Map $type: OpenAPI dictionaries must have keys of type String")
|
||||
}
|
||||
generateKTypeKontent(valType!!, cache)
|
||||
val valClass = valType.classifier as KClass<*>
|
||||
val valClass = valType!!.classifier as KClass<*>
|
||||
val valClassName = valClass.simpleName
|
||||
val referenceName = genericNameAdapter(type, clazz)
|
||||
val valueReference = when (valClass.isSealed) {
|
||||
@ -43,6 +42,7 @@ object MapHandler : SchemaHandler {
|
||||
})
|
||||
}
|
||||
false -> {
|
||||
generateKTypeKontent(valType, cache)
|
||||
val schema = cache[valClassName] ?: error("$valClassName not found")
|
||||
postProcessSchema(schema, valClassName!!)
|
||||
}
|
||||
|
@ -130,6 +130,9 @@
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -145,6 +148,9 @@
|
||||
"c": {
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -165,6 +171,9 @@
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -180,6 +189,9 @@
|
||||
"c": {
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -199,6 +211,9 @@
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -214,6 +229,9 @@
|
||||
"c": {
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -102,6 +102,9 @@
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -117,6 +120,9 @@
|
||||
"c": {
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -64,6 +64,9 @@
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -79,6 +82,9 @@
|
||||
"c": {
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -60,14 +60,13 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"FlibbityGibbit": {
|
||||
"properties": {},
|
||||
"type": "object"
|
||||
},
|
||||
"SimpleGibbit": {
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -83,6 +82,9 @@
|
||||
"c": {
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -61,6 +61,9 @@
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@ -76,6 +79,9 @@
|
||||
"c": {
|
||||
"format": "int32",
|
||||
"type": "integer"
|
||||
},
|
||||
"z": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
@ -202,10 +202,12 @@ data class OptionalParams(
|
||||
@Param(ParamType.QUERY) val notRequired: String?
|
||||
)
|
||||
|
||||
sealed class FlibbityGibbit
|
||||
sealed class FlibbityGibbit {
|
||||
abstract val z: String
|
||||
}
|
||||
|
||||
data class SimpleGibbit(val a: String) : FlibbityGibbit()
|
||||
data class ComplexGibbit(val b: String, val c: Int) : FlibbityGibbit()
|
||||
data class SimpleGibbit(val a: String, override val z: String = "z") : FlibbityGibbit()
|
||||
data class ComplexGibbit(val b: String, val c: Int, override val z: String = "z") : FlibbityGibbit()
|
||||
|
||||
sealed interface SlammaJamma
|
||||
|
||||
|
Reference in New Issue
Block a user