From ff600fa6a89e960d300fec6da5b75884400837a0 Mon Sep 17 00:00:00 2001 From: "Xeroman.K" Date: Wed, 21 Feb 2024 23:03:50 +0900 Subject: [PATCH] fix: Schema is null (#260) --- .../restdocs/apispec/openapi3/OpenApi3Generator.kt | 10 +++++----- .../restdocs/apispec/openapi3/OpenApi3GeneratorTest.kt | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/restdocs-api-spec-openapi3-generator/src/main/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3Generator.kt b/restdocs-api-spec-openapi3-generator/src/main/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3Generator.kt index 00b46cd..54d5918 100644 --- a/restdocs-api-spec-openapi3-generator/src/main/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3Generator.kt +++ b/restdocs-api-spec-openapi3-generator/src/main/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3Generator.kt @@ -86,7 +86,7 @@ object OpenApi3Generator { private fun OpenAPI.makeSubSchema() { val schemas = this.components.schemas - val subSchemas = mutableMapOf>() + val subSchemas = mutableMapOf?>() schemas.forEach { val schema = it.value if (schema.properties != null) { @@ -99,14 +99,14 @@ object OpenApi3Generator { } } - private fun makeSubSchema(schemas: MutableMap>, properties: Map>) { - properties.asSequence().filter { it.value.title != null }.forEach { + private fun makeSubSchema(schemas: MutableMap?>, properties: Map?>) { + properties.asSequence().filter { it.value?.title != null }.forEach { val objectMapper = jacksonObjectMapper() val subSchema = it.value val strSubSchema = objectMapper.writeValueAsString(subSchema) - val copySchema = objectMapper.readValue(strSubSchema, subSchema.javaClass) + val copySchema = objectMapper.readValue(strSubSchema, subSchema?.javaClass) val schemaTitle = copySchema.title - subSchema.`$ref`("#/components/schemas/$schemaTitle") + subSchema?.`$ref`("#/components/schemas/$schemaTitle") schemas[schemaTitle] = copySchema makeSubSchema(schemas, copySchema.properties) } diff --git a/restdocs-api-spec-openapi3-generator/src/test/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3GeneratorTest.kt b/restdocs-api-spec-openapi3-generator/src/test/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3GeneratorTest.kt index a87b115..c135aac 100644 --- a/restdocs-api-spec-openapi3-generator/src/test/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3GeneratorTest.kt +++ b/restdocs-api-spec-openapi3-generator/src/test/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3GeneratorTest.kt @@ -1100,6 +1100,11 @@ class OpenApi3GeneratorTest { description = "product id", type = "STRING" ), + FieldDescriptor( + path = "null_value", + description = "null_value", + type = "NULL" + ), FieldDescriptor( path = "option", description = "option",