Skip to content

Commit ff600fa

Browse files
authored
fix: Schema is null (#260)
1 parent e16f028 commit ff600fa

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

restdocs-api-spec-openapi3-generator/src/main/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3Generator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ object OpenApi3Generator {
8686

8787
private fun OpenAPI.makeSubSchema() {
8888
val schemas = this.components.schemas
89-
val subSchemas = mutableMapOf<String, Schema<Any>>()
89+
val subSchemas = mutableMapOf<String, Schema<Any>?>()
9090
schemas.forEach {
9191
val schema = it.value
9292
if (schema.properties != null) {
@@ -99,14 +99,14 @@ object OpenApi3Generator {
9999
}
100100
}
101101

102-
private fun makeSubSchema(schemas: MutableMap<String, Schema<Any>>, properties: Map<String, Schema<Any>>) {
103-
properties.asSequence().filter { it.value.title != null }.forEach {
102+
private fun makeSubSchema(schemas: MutableMap<String, Schema<Any>?>, properties: Map<String, Schema<Any>?>) {
103+
properties.asSequence().filter { it.value?.title != null }.forEach {
104104
val objectMapper = jacksonObjectMapper()
105105
val subSchema = it.value
106106
val strSubSchema = objectMapper.writeValueAsString(subSchema)
107-
val copySchema = objectMapper.readValue(strSubSchema, subSchema.javaClass)
107+
val copySchema = objectMapper.readValue(strSubSchema, subSchema?.javaClass)
108108
val schemaTitle = copySchema.title
109-
subSchema.`$ref`("#/components/schemas/$schemaTitle")
109+
subSchema?.`$ref`("#/components/schemas/$schemaTitle")
110110
schemas[schemaTitle] = copySchema
111111
makeSubSchema(schemas, copySchema.properties)
112112
}

restdocs-api-spec-openapi3-generator/src/test/kotlin/com/epages/restdocs/apispec/openapi3/OpenApi3GeneratorTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,11 @@ class OpenApi3GeneratorTest {
11001100
description = "product id",
11011101
type = "STRING"
11021102
),
1103+
FieldDescriptor(
1104+
path = "null_value",
1105+
description = "null_value",
1106+
type = "NULL"
1107+
),
11031108
FieldDescriptor(
11041109
path = "option",
11051110
description = "option",

0 commit comments

Comments
 (0)