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

Automatically discover oneOf for sealed classes in OpenAPI #46694

Open
LarsSven opened this issue Mar 10, 2025 · 1 comment
Open

Automatically discover oneOf for sealed classes in OpenAPI #46694

LarsSven opened this issue Mar 10, 2025 · 1 comment

Comments

@LarsSven
Copy link
Contributor

Description

In Kotlin, imagine we have a class like this:

@Schema(
    oneOf = [InputResourceReference.Action::class, InputResourceReference.Assignment::class],
    discriminatorProperty = "type",
    discriminatorMapping = [
        DiscriminatorMapping(value = "action", schema = InputResourceReference.Action::class),
        DiscriminatorMapping(value = "assignment", schema = InputResourceReference.Assignment::class)
    ],
    properties = [
        SchemaProperty(name = "type", implementation = String::class),
    ]
)
@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.PROPERTY,
    property = "type"
)
sealed class InputResourceReference {
    @JsonTypeName("action")
    data class Action(
        val stage: String,
        val job: String,
        val action: String,
        val resourceUri: URI,
    ): InputResourceReference()

    @JsonTypeName("assignment")
    data class Assignment(val uri: URI): InputResourceReference()
}

It would be nice if OpenAPI could automatically determine the oneOf field (and possibly even the discriminator, though that would be harder) since it can be easily determined for sealed classes.

Implementation ideas

Jackson already implements this as can be seen in the example, so it could serve as a reference.

Copy link

quarkus-bot bot commented Mar 10, 2025

/cc @EricWittmann (openapi), @MikeEdgar (openapi), @geoand (kotlin), @phillip-kruger (openapi)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant