fix: null ref (#286)
This commit is contained in:
@ -7,6 +7,7 @@
|
|||||||
### Changed
|
### Changed
|
||||||
- Can now put redoc route behind authentication
|
- Can now put redoc route behind authentication
|
||||||
- Fixed issue where type erasure was breaking nested generics
|
- Fixed issue where type erasure was breaking nested generics
|
||||||
|
- Fix bug with null references not displaying properly on properties
|
||||||
|
|
||||||
### Remove
|
### Remove
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import io.bkbn.kompendium.core.util.TestModules.notarizedPut
|
|||||||
import io.bkbn.kompendium.core.util.TestModules.nullableEnumField
|
import io.bkbn.kompendium.core.util.TestModules.nullableEnumField
|
||||||
import io.bkbn.kompendium.core.util.TestModules.nullableField
|
import io.bkbn.kompendium.core.util.TestModules.nullableField
|
||||||
import io.bkbn.kompendium.core.util.TestModules.nullableNestedObject
|
import io.bkbn.kompendium.core.util.TestModules.nullableNestedObject
|
||||||
|
import io.bkbn.kompendium.core.util.TestModules.nullableReference
|
||||||
import io.bkbn.kompendium.core.util.TestModules.polymorphicCollectionResponse
|
import io.bkbn.kompendium.core.util.TestModules.polymorphicCollectionResponse
|
||||||
import io.bkbn.kompendium.core.util.TestModules.polymorphicMapResponse
|
import io.bkbn.kompendium.core.util.TestModules.polymorphicMapResponse
|
||||||
import io.bkbn.kompendium.core.util.TestModules.polymorphicResponse
|
import io.bkbn.kompendium.core.util.TestModules.polymorphicResponse
|
||||||
@ -191,6 +192,9 @@ class KompendiumTest : DescribeSpec({
|
|||||||
it("Can have a nullable enum as a member field") {
|
it("Can have a nullable enum as a member field") {
|
||||||
openApiTestAllSerializers("T0037__nullable_enum_field.json") { nullableEnumField() }
|
openApiTestAllSerializers("T0037__nullable_enum_field.json") { nullableEnumField() }
|
||||||
}
|
}
|
||||||
|
it("Can have a nullable reference without impacting base type") {
|
||||||
|
openApiTestAllSerializers("T0041__nullable_reference.json") { nullableReference() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
describe("Constraints") {
|
describe("Constraints") {
|
||||||
// TODO Assess strategies here
|
// TODO Assess strategies here
|
||||||
|
@ -8,6 +8,7 @@ import io.bkbn.kompendium.core.fixtures.ExceptionResponse
|
|||||||
import io.bkbn.kompendium.core.fixtures.Flibbity
|
import io.bkbn.kompendium.core.fixtures.Flibbity
|
||||||
import io.bkbn.kompendium.core.fixtures.FlibbityGibbit
|
import io.bkbn.kompendium.core.fixtures.FlibbityGibbit
|
||||||
import io.bkbn.kompendium.core.fixtures.Gibbity
|
import io.bkbn.kompendium.core.fixtures.Gibbity
|
||||||
|
import io.bkbn.kompendium.core.fixtures.ManyThings
|
||||||
import io.bkbn.kompendium.core.fixtures.MultiNestedGenerics
|
import io.bkbn.kompendium.core.fixtures.MultiNestedGenerics
|
||||||
import io.bkbn.kompendium.core.fixtures.NullableEnum
|
import io.bkbn.kompendium.core.fixtures.NullableEnum
|
||||||
import io.bkbn.kompendium.core.fixtures.NullableField
|
import io.bkbn.kompendium.core.fixtures.NullableField
|
||||||
@ -579,6 +580,8 @@ object TestModules {
|
|||||||
|
|
||||||
fun Routing.nullableEnumField() = basicGetGenerator<NullableEnum>()
|
fun Routing.nullableEnumField() = basicGetGenerator<NullableEnum>()
|
||||||
|
|
||||||
|
fun Routing.nullableReference() = basicGetGenerator<ManyThings>()
|
||||||
|
|
||||||
fun Routing.dateTimeString() = basicGetGenerator<DateTimeString>()
|
fun Routing.dateTimeString() = basicGetGenerator<DateTimeString>()
|
||||||
|
|
||||||
fun Routing.headerParameter() = basicGetGenerator<TestResponse>(
|
fun Routing.headerParameter() = basicGetGenerator<TestResponse>(
|
||||||
|
98
core/src/test/resources/T0041__nullable_reference.json
Normal file
98
core/src/test/resources/T0041__nullable_reference.json
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
{
|
||||||
|
"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/ManyThings"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deprecated": false
|
||||||
|
},
|
||||||
|
"parameters": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"webhooks": {},
|
||||||
|
"components": {
|
||||||
|
"schemas": {
|
||||||
|
"Something": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"a": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"b": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "int32"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"a",
|
||||||
|
"b"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ManyThings": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"someA": {
|
||||||
|
"$ref": "#/components/schemas/Something"
|
||||||
|
},
|
||||||
|
"someB": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "#/components/schemas/Something"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"someA"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"securitySchemes": {}
|
||||||
|
},
|
||||||
|
"security": [],
|
||||||
|
"tags": []
|
||||||
|
}
|
@ -131,3 +131,10 @@ data class Page<T>(
|
|||||||
data class MultiNestedGenerics<T, E>(
|
data class MultiNestedGenerics<T, E>(
|
||||||
val content: Map<T, E>
|
val content: Map<T, E>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class Something(val a: String, val b: Int)
|
||||||
|
|
||||||
|
data class ManyThings(
|
||||||
|
val someA: Something,
|
||||||
|
val someB: Something?
|
||||||
|
)
|
||||||
|
@ -31,7 +31,13 @@ object SimpleObjectHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prop.name to schema
|
// TODO This is kinda hacky 👀 And might break in certain edge cases?
|
||||||
|
val nullCheckSchema = when (prop.returnType.isMarkedNullable && schema !is OneOfDefinition) {
|
||||||
|
true -> OneOfDefinition(NullableDefinition(), schema)
|
||||||
|
false -> schema
|
||||||
|
}
|
||||||
|
|
||||||
|
prop.name to nullCheckSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
val required = clazz.memberProperties.filterNot { prop -> prop.returnType.isMarkedNullable }
|
val required = clazz.memberProperties.filterNot { prop -> prop.returnType.isMarkedNullable }
|
||||||
|
Reference in New Issue
Block a user