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 default array issue. #315

Merged
merged 4 commits into from
Sep 16, 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 @@ -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
16 changes: 16 additions & 0 deletions src/test/resources/examples/defaultValues/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,19 @@ components:
type: string
format: byte
default: U3dhZ2dlciByb2Nrcw==
ignored_array_default:
type: array
default: []
items:
type: string
ignored_object_default:
type: object
properties:
name:
type: string
age:
type: integer
default:
name: "John Doe"
age: 30

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import com.fasterxml.jackson.`annotation`.JsonProperty
import java.math.BigDecimal
import java.net.URI
import java.util.Base64
import javax.validation.Valid
import javax.validation.constraints.NotNull
import kotlin.Boolean
import kotlin.ByteArray
import kotlin.Int
import kotlin.String
import kotlin.collections.List

public data class PersonWithDefaults(
@param:JsonProperty("required_so_default_ignored")
Expand Down Expand Up @@ -48,4 +50,11 @@ public data class PersonWithDefaults(
@get:JsonProperty("byte_type")
@get:NotNull
public val byteType: ByteArray = Base64.getDecoder().decode("U3dhZ2dlciByb2Nrcw=="),
@param:JsonProperty("ignored_array_default")
@get:JsonProperty("ignored_array_default")
public val ignoredArrayDefault: List<String>? = null,
@param:JsonProperty("ignored_object_default")
@get:JsonProperty("ignored_object_default")
@get:Valid
public val ignoredObjectDefault: PersonWithDefaultsIgnoredObjectDefault? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package examples.defaultValues.models

import com.fasterxml.jackson.`annotation`.JsonProperty
import kotlin.Int
import kotlin.String

public data class PersonWithDefaultsIgnoredObjectDefault(
@param:JsonProperty("name")
@get:JsonProperty("name")
public val name: String? = null,
@param:JsonProperty("age")
@get:JsonProperty("age")
public val age: Int? = null,
)