fix: fixed generic property enrichment (#454)
This commit is contained in:
@ -133,8 +133,8 @@ object SimpleObjectHandler {
|
||||
?: error("This indicates a bug in Kompendium, please open a GitHub issue")
|
||||
return SchemaGenerator.fromTypeToSchema(type, cache, schemaConfigurator, propEnrichment?.typeEnrichment).let {
|
||||
if (it.isOrContainsObjectOrEnumDef()) {
|
||||
cache[type.getSlug(propEnrichment)] = it
|
||||
ReferenceDefinition(type.getReferenceSlug(propEnrichment))
|
||||
cache[type.getSlug(propEnrichment?.typeEnrichment)] = it
|
||||
ReferenceDefinition(type.getReferenceSlug(propEnrichment?.typeEnrichment))
|
||||
} else {
|
||||
it
|
||||
}
|
||||
|
@ -7,11 +7,12 @@ import io.bkbn.kompendium.core.fixtures.ObjectWithEnum
|
||||
import io.bkbn.kompendium.core.fixtures.SerialNameObject
|
||||
import io.bkbn.kompendium.core.fixtures.SimpleEnum
|
||||
import io.bkbn.kompendium.core.fixtures.SlammaJamma
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot
|
||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
|
||||
import io.bkbn.kompendium.core.fixtures.TransientObject
|
||||
import io.bkbn.kompendium.core.fixtures.UnbackedObject
|
||||
import io.bkbn.kompendium.core.fixtures.GenericObject
|
||||
import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot
|
||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||
import io.kotest.assertions.json.shouldEqualJson
|
||||
@ -62,6 +63,9 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
it("Can generate the schema for object with SerialName annotation") {
|
||||
jsonSchemaTest<SerialNameObject>("T0020__serial_name_object.json")
|
||||
}
|
||||
it("Can generate the schema for object with generic property") {
|
||||
jsonSchemaTest<GenericObject<TestSimpleRequest>>("T0024__generic_object.json")
|
||||
}
|
||||
}
|
||||
describe("Enums") {
|
||||
it("Can generate the schema for a simple enum") {
|
||||
@ -135,6 +139,24 @@ class SchemaGeneratorTest : DescribeSpec({
|
||||
}
|
||||
)
|
||||
}
|
||||
it("Can properly assign a reference to a generic object") {
|
||||
jsonSchemaTest<GenericObject<TestSimpleRequest>>(
|
||||
snapshotName = "T0025__enrichment_generic_object.json",
|
||||
enrichment = TypeEnrichment("generic") {
|
||||
GenericObject<TestSimpleRequest>::data {
|
||||
description = "This is a generic param"
|
||||
typeEnrichment = TypeEnrichment("simple") {
|
||||
TestSimpleRequest::a {
|
||||
description = "This is a simple description"
|
||||
}
|
||||
TestSimpleRequest::b {
|
||||
deprecated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}) {
|
||||
companion object {
|
||||
|
11
json-schema/src/test/resources/T0024__generic_object.json
Normal file
11
json-schema/src/test/resources/T0024__generic_object.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/components/schemas/TestSimpleRequest"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
]
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"description": "This is a generic param",
|
||||
"$ref": "#/components/schemas/TestSimpleRequest-simple"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"data"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user