fix: enum type def (#563)
This commit is contained in:
@ -35,7 +35,7 @@ class KotlinXSchemaConfigurator : SchemaConfigurator {
|
||||
required = implementationSchema.required?.plus("type"),
|
||||
properties = implementationSchema.properties?.plus(
|
||||
mapOf(
|
||||
"type" to EnumDefinition("string", enum = setOf(determineTypeQualifier(implementationType)))
|
||||
"type" to EnumDefinition(enum = setOf(determineTypeQualifier(implementationType)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -4,7 +4,6 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class EnumDefinition(
|
||||
val type: String,
|
||||
val enum: Set<String>,
|
||||
override val deprecated: Boolean? = null,
|
||||
override val description: String? = null,
|
||||
|
@ -4,6 +4,7 @@ import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.SchemaConfigurator
|
||||
import io.bkbn.kompendium.json.schema.SchemaGenerator
|
||||
import io.bkbn.kompendium.json.schema.definition.ArrayDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.EnumDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.bkbn.kompendium.json.schema.definition.NullableDefinition
|
||||
import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
||||
@ -23,7 +24,7 @@ object CollectionHandler {
|
||||
val collectionType = type.arguments.first().type
|
||||
?: error("This indicates a bug in Kompendium, please open a GitHub issue!")
|
||||
val typeSchema = SchemaGenerator.fromTypeToSchema(collectionType, cache, schemaConfigurator, enrichment).let {
|
||||
if (it is TypeDefinition && it.type == "object") {
|
||||
if ((it is TypeDefinition && it.type == "object") || it is EnumDefinition) {
|
||||
cache[collectionType.getSlug(enrichment)] = it
|
||||
ReferenceDefinition(collectionType.getReferenceSlug(enrichment))
|
||||
} else {
|
||||
|
@ -19,6 +19,6 @@ object EnumHandler {
|
||||
cache[type.getSlug(enrichment)] = ReferenceDefinition(type.getReferenceSlug(enrichment))
|
||||
|
||||
val options = clazz.java.enumConstants.map { it.toString() }.toSet()
|
||||
return EnumDefinition(type = "string", enum = options)
|
||||
return EnumDefinition(enum = options)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
{
|
||||
"enum": [ "ONE", "TWO" ],
|
||||
"type": "string"
|
||||
"enum": [ "ONE", "TWO" ]
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
{
|
||||
"enum": [ "ONE", "TWO" ],
|
||||
"type": "string"
|
||||
"enum": [ "ONE", "TWO" ]
|
||||
}
|
||||
|
Reference in New Issue
Block a user