diff --git a/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt b/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt index 026c22e76..448291dbe 100644 --- a/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt +++ b/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt @@ -14,6 +14,7 @@ import io.bkbn.kompendium.core.util.TestModules.singleException import io.bkbn.kompendium.core.util.TestModules.genericException import io.bkbn.kompendium.core.util.TestModules.genericPolymorphicResponse import io.bkbn.kompendium.core.util.TestModules.genericPolymorphicResponseMultipleImpls +import io.bkbn.kompendium.core.util.TestModules.gnarlyGenericResponse import io.bkbn.kompendium.core.util.TestModules.headerParameter import io.bkbn.kompendium.core.util.TestModules.multipleExceptions import io.bkbn.kompendium.core.util.TestModules.nestedGenericCollection @@ -167,6 +168,9 @@ class KompendiumTest : DescribeSpec({ it("Can support nested generics with multiple type parameters") { openApiTestAllSerializers("T0040__nested_generic_multiple_type_params.json") { nestedGenericMultipleParamsCollection() } } + it("Can handle a really gnarly generic example") { + openApiTestAllSerializers("T0043__gnarly_generic_example.json") { gnarlyGenericResponse() } + } } describe("Miscellaneous") { xit("Can generate the necessary ReDoc home page") { diff --git a/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt b/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt index 324bd6cee..e2d936254 100644 --- a/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt +++ b/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt @@ -1,5 +1,6 @@ package io.bkbn.kompendium.core.util +import io.bkbn.kompendium.core.fixtures.Barzo import io.bkbn.kompendium.core.fixtures.ColumnSchema import io.bkbn.kompendium.core.fixtures.ComplexRequest import io.bkbn.kompendium.core.fixtures.DateTimeString @@ -7,6 +8,7 @@ import io.bkbn.kompendium.core.fixtures.DefaultField import io.bkbn.kompendium.core.fixtures.ExceptionResponse import io.bkbn.kompendium.core.fixtures.Flibbity import io.bkbn.kompendium.core.fixtures.FlibbityGibbit +import io.bkbn.kompendium.core.fixtures.Foosy import io.bkbn.kompendium.core.fixtures.Gibbity import io.bkbn.kompendium.core.fixtures.ManyThings import io.bkbn.kompendium.core.fixtures.MultiNestedGenerics @@ -564,6 +566,8 @@ object TestModules { fun Routing.simpleGenericResponse() = basicGetGenerator>() + fun Routing.gnarlyGenericResponse() = basicGetGenerator, String>>() + fun Routing.nestedGenericResponse() = basicGetGenerator>>() fun Routing.genericPolymorphicResponse() = basicGetGenerator>() diff --git a/core/src/test/resources/T0043__gnarly_generic_example.json b/core/src/test/resources/T0043__gnarly_generic_example.json new file mode 100644 index 000000000..5c53d5ea0 --- /dev/null +++ b/core/src/test/resources/T0043__gnarly_generic_example.json @@ -0,0 +1,91 @@ +{ + "openapi": "3.1.0", + "jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema", + "info": { + "title": "Test API", + "version": "1.33.7", + "description": "An amazing, fully-ish 😉 generated API spec", + "termsOfService": "https://example.com", + "contact": { + "name": "Homer Simpson", + "url": "https://gph.is/1NPUDiM", + "email": "chunkylover53@aol.com" + }, + "license": { + "name": "MIT", + "url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE" + } + }, + "servers": [ + { + "url": "https://myawesomeapi.com", + "description": "Production instance of my API" + }, + { + "url": "https://staging.myawesomeapi.com", + "description": "Where the fun stuff happens" + } + ], + "paths": { + "/": { + "get": { + "tags": [], + "summary": "Great Summary!", + "description": "testing more", + "parameters": [], + "responses": { + "200": { + "description": "A Successful Endeavor", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Foosy-Barzo-String" + } + } + } + } + }, + "deprecated": false + }, + "parameters": [] + } + }, + "webhooks": {}, + "components": { + "schemas": { + "Foosy-Barzo-String": { + "type": "object", + "properties": { + "otherThing": { + "items": { + "type": "string" + }, + "type": "array" + }, + "test": { + "$ref": "#/components/schemas/Barzo-Int" + } + }, + "required": [ + "otherThing", + "test" + ] + }, + "Barzo-Int": { + "type": "object", + "properties": { + "result": { + "type": "number", + "format": "int32" + } + }, + "required": [ + "result" + ] + } + }, + "securitySchemes": {} + }, + "security": [], + "tags": [] +} diff --git a/core/src/testFixtures/kotlin/io/bkbn/kompendium/core/fixtures/TestModels.kt b/core/src/testFixtures/kotlin/io/bkbn/kompendium/core/fixtures/TestModels.kt index 5e506ba4b..cf5dcd6fa 100644 --- a/core/src/testFixtures/kotlin/io/bkbn/kompendium/core/fixtures/TestModels.kt +++ b/core/src/testFixtures/kotlin/io/bkbn/kompendium/core/fixtures/TestModels.kt @@ -138,3 +138,6 @@ data class ManyThings( val someA: Something, val someB: Something? ) + +data class Foosy(val test: T, val otherThing: List) +data class Barzo(val result: G) diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt index 99edf33d9..4373b0f3e 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt @@ -96,7 +96,7 @@ object SimpleObjectHandler { return SchemaGenerator.fromTypeToSchema(type, cache).let { if (it.isOrContainsObjectDef()) { cache[type.getSimpleSlug()] = it - ReferenceDefinition(prop.returnType.getReferenceSlug()) + ReferenceDefinition(type.getReferenceSlug()) } else { it }