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

Issue with default value for additional property (oneOf) #270

Merged
merged 2 commits into from
Mar 6, 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 @@ -154,7 +154,8 @@ object KaizenParserExtensions {
fun Schema.isDiscriminatorProperty(api: OpenApi3, prop: Map.Entry<String, Schema>): Boolean =
discriminator?.propertyName == prop.key ||
findOneOfSuperInterface(api.schemas.values.toList()).any { oneOf ->
oneOf.discriminator?.mappings?.values?.any { it.endsWith("/$name") } ?: false
oneOf.discriminator?.propertyName == prop.key
&& oneOf.discriminator?.mappings?.values?.any { it.endsWith("/$name") } ?: false
}

fun Schema.findOneOfSuperInterface(allSchemas: List<Schema>): Set<Schema> {
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/examples/discriminatedOneOf/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ components:
type: object
required:
- status
- mode
properties:
status:
$ref: '#/components/schemas/Status'
mode:
type: string
enum:
- mode1
- mode2
18 changes: 18 additions & 0 deletions src/test/resources/examples/discriminatedOneOf/models/Models.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,30 @@ public data class StateA(
) : State

public data class StateB(
@get:JsonProperty("mode")
@get:NotNull
public val mode: StateBMode,
@get:JsonProperty("status")
@get:NotNull
@param:JsonProperty("status")
public val status: Status = Status.B,
) : State

public enum class StateBMode(
@JsonValue
public val `value`: String,
) {
MODE1("mode1"),
MODE2("mode2"),
;

public companion object {
private val mapping: Map<String, StateBMode> = values().associateBy(StateBMode::value)

public fun fromValue(`value`: String): StateBMode? = mapping[value]
}
}

public enum class Status(
@JsonValue
public val `value`: String,
Expand Down
Loading