Skip to content

Commit

Permalink
Fix default array issue.
Browse files Browse the repository at this point in the history
We can only support basic defaults for field types, and should ignore any more complicated defaults for now. Closes #312
  • Loading branch information
cjbooms committed Sep 16, 2024
1 parent 6528da2 commit 8e2e419
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ object PropertyUtils {
}

fun PropertyInfo.isNullable() = when (this) {
is PropertyInfo.Field, is PropertyInfo.ListField, is PropertyInfo.MapField,
is PropertyInfo.Field -> !isRequired && schema.default == null || schema.isNullable
is PropertyInfo.ListField, is PropertyInfo.MapField,
is PropertyInfo.ObjectRefField, is PropertyInfo.ObjectInlinedField ->
!isRequired && schema.default == null || schema.isNullable
!isRequired || schema.isNullable
else -> !isRequired
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/examples/arrays/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ components:
properties:
some-array-prop:
type: string
array_with_empty_default:
type: array
default: []
items:
type: string
a-nullable-array:
type: array
nullable: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public data class ContainsArrayOfArrays(
@get:JsonProperty("absent-object-type-in-array")
@get:Valid
public val absentObjectTypeInArray: List<ContainsArrayOfArraysAbsentObjectTypeInArray>? = null,
@param:JsonProperty("array_with_empty_default")
@get:JsonProperty("array_with_empty_default")
public val arrayWithEmptyDefault: List<String>? = null,
@param:JsonProperty("a-nullable-array")
@get:JsonProperty("a-nullable-array")
public val aNullableArray: List<String?>? = null,
Expand Down

0 comments on commit 8e2e419

Please sign in to comment.