Skip to content

Commit

Permalink
GH-220 Generate "nullable: true" for types explicitly marked as nulla…
Browse files Browse the repository at this point in the history
…ble (Resolve #220)
  • Loading branch information
dzikoysk committed Jun 7, 2024
1 parent 634e9b7 commit 00a33c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data class KotlinEntity(
val name: String,
val primitive: Int,
val custom: Elements,
val oneOfResult: Result
val oneOfResult: Result,
val nullable: Any?,
)

@JsonSchema(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ internal class ComponentAnnotationsTest : OpenApiAnnotationProcessorSpecificatio
"properties": {
"testProperty": {
"type": "number",
"nullable": true,
"format": "double"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,25 @@ internal fun ClassDefinition.findAllProperties(requireNonNulls: Boolean): Collec
else -> requireNonNulls && isNotNull
}

val extra = mutableMapOf<String, Any?>()

val isExplicitlyNullable = when {
customType?.nullability == Nullability.NULLABLE -> true
property.hasAnnotation("Nullable") -> true
else -> false
}

if (isExplicitlyNullable) {
extra["nullable"] = true
}

properties.add(
Property(
name = name,
type = propertyType.toClassDefinition(),
composition = findCompositionInElement(context, property),
required = required,
extra = property.findExtra(context)
extra = extra + property.findExtra(context)
)
)
}
Expand Down

0 comments on commit 00a33c9

Please sign in to comment.