Skip to content

Commit

Permalink
fix: Schema is null (ePages-de#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
xeromank authored Feb 21, 2024
1 parent e16f028 commit ff600fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object OpenApi3Generator {

private fun OpenAPI.makeSubSchema() {
val schemas = this.components.schemas
val subSchemas = mutableMapOf<String, Schema<Any>>()
val subSchemas = mutableMapOf<String, Schema<Any>?>()
schemas.forEach {
val schema = it.value
if (schema.properties != null) {
Expand All @@ -99,14 +99,14 @@ object OpenApi3Generator {
}
}

private fun makeSubSchema(schemas: MutableMap<String, Schema<Any>>, properties: Map<String, Schema<Any>>) {
properties.asSequence().filter { it.value.title != null }.forEach {
private fun makeSubSchema(schemas: MutableMap<String, Schema<Any>?>, properties: Map<String, Schema<Any>?>) {
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ff600fa

Please sign in to comment.