Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Schema is null #260

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading