springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

Nested oneOf and allOf when using oneOf with @JsonSubTypes

Open ghovhannesVM opened this issue 1 year ago • 2 comments

Describe the bug When I use @JsonSubTypes with @Schema(oneOf = {..}), the model schema shows infinite nested oneOf and allOf. When I remove @JsonSubTypes from the parent model, everything works well. Am i doing something wrong or is this expected behaviour ?

Expected behavior The expected behavior is to show only the oneOf field. After selecting one of the child classes, it should stop expanding.

Screenshots The structure of the model Screenshot 2024-07-23 at 18 10 25

The output Screenshot 2024-07-23 at 18 13 47

Versions

  • springdoc-openapi-starter-webmvc-ui 2.1.0

ghovhannesVM avatar Jul 23 '24 14:07 ghovhannesVM

Also mentioned in #2575 and #2577, which have since been closed

This is still broken in 2.6.0

We ran into a similar (maybe the same?) issue when trying to use polymorphic types, like:

@JsonTypeInfo(use = NAME, include = PROPERTY, property = DISCRIMINATOR_PROPERTY)
@JsonSubTypes(
    Type(value = Activate::class, name = ACTIVATE)
)
@Schema(
    subTypes = [Activate::class],
    oneOf = [Activate::class],
    discriminatorProperty = DISCRIMINATOR_PROPERTY,
    discriminatorMapping = [
        DiscriminatorMapping(value = ACTIVATE, schema = Activate::class)
    ]
)
sealed interface PolymorphicEvent {
    @Schema(requiredProperties = [DISCRIMINATOR_PROPERTY])
    @SchemaProperty(name = DISCRIMINATOR_PROPERTY, schema = Schema(allowableValues = [ACTIVATE]))
    data object Activate : PolymorphicEvent

    companion object {
        const val DISCRIMINATOR_PROPERTY = "type"
        const val ACTIVATE = "ACTIVATE"
    }
}

Defining this in 2.3.0 would work, but totally broke our Schema view in SwaggerUI after 2.5.0, where the oneOf definition just references itself recursively forever. (This might even be worth a second issue)

image

LouisXhaferi avatar Jul 26 '24 08:07 LouisXhaferi

I have the same probleme in 2.6.0

ilaoud avatar Jul 26 '24 12:07 ilaoud

Do you have any updates on this? Thanks!

Nhattd97 avatar Sep 04 '24 03:09 Nhattd97

@ghovhannesVM,

Not reproducible. Feel free to provide a Minimal, Reproducible Example - with HelloController that reproduces the problem.

This ticket will be closed, but can be reopened if your provide the reproducible sample.

bnasslahsen avatar Sep 22 '24 12:09 bnasslahsen