fix: add missing mapping of BooleanEnrichment to EnrichmentHandler (#655)

This commit is contained in:
Johannes Hoppenstedt
2024-11-11 20:33:45 +01:00
committed by GitHub
parent 4a9165fd3a
commit 636bf65c36
15 changed files with 89 additions and 14 deletions

View File

@ -1,5 +1,6 @@
package io.bkbn.kompendium.json.schema.handler
import io.bkbn.kompendium.enrichment.BooleanEnrichment
import io.bkbn.kompendium.enrichment.CollectionEnrichment
import io.bkbn.kompendium.enrichment.Enrichment
import io.bkbn.kompendium.enrichment.MapEnrichment
@ -15,6 +16,7 @@ import io.bkbn.kompendium.json.schema.definition.TypeDefinition
object EnrichmentHandler {
fun Enrichment.applyToSchema(schema: JsonSchema): JsonSchema = when (this) {
is BooleanEnrichment -> applyToSchema(schema)
is NumberEnrichment -> applyToSchema(schema)
is StringEnrichment -> applyToSchema(schema)
is CollectionEnrichment<*> -> applyToSchema(schema)
@ -39,6 +41,11 @@ object EnrichmentHandler {
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
}
private fun BooleanEnrichment.applyToSchema(schema: JsonSchema): JsonSchema = when (schema) {
is TypeDefinition -> schema.copyBooleanEnrichment(this)
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
}
private fun NumberEnrichment.applyToSchema(schema: JsonSchema): JsonSchema = when (schema) {
is TypeDefinition -> schema.copyNumberEnrichment(this)
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
@ -49,6 +56,13 @@ object EnrichmentHandler {
else -> error("Incorrect enrichment type for enrichment id: ${this.id}")
}
private fun TypeDefinition.copyBooleanEnrichment(
enrichment: BooleanEnrichment
): TypeDefinition = copy(
deprecated = enrichment.deprecated,
description = enrichment.description,
)
private fun TypeDefinition.copyNumberEnrichment(
enrichment: NumberEnrichment
): TypeDefinition = copy(

View File

@ -7,10 +7,14 @@
"b": {
"type": "number",
"format": "int32"
},
"c": {
"type": "boolean"
}
},
"required": [
"a",
"b"
"b",
"c"
]
}

View File

@ -7,10 +7,14 @@
"b": {
"type": "number",
"format": "int32"
},
"c": {
"type": "boolean"
}
},
"required": [
"a",
"b"
"b",
"c"
]
}

View File

@ -9,10 +9,14 @@
"type": "number",
"format": "int32",
"deprecated": true
},
"c": {
"type": "boolean"
}
},
"required": [
"a",
"b"
"b",
"c"
]
}