How can the property example for discriminator be done?

Viewed 17

I'm generating swagger description with openapi annotations.

There is a case with polymorphic dto's with a discriminator property type that I can't handle:

@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.PROPERTY,
    property = "type"
)
@JsonSubTypes(
    JsonSubTypes.Type(value = ListValue::class, name = "in"),
    JsonSubTypes.Type(value = ExactValue::class, name = "is")
)
abstract class CompositeValue

and two subclasses:

@JsonTypeName("is")
data class ExactValue(

    @get:Schema(
        description = "Single condition value.",
        example = "2"
    )
    val value: String
) : CompositeValue()

@JsonTypeName("in")
data class ListValue(

    @get:Schema(
        description = "Multiple condition value.",
        example = "[2, 4, 6]"
    )
    val value: List<String>,
) : CompositeValue()

Openapi generates swagger example type field example "string", nut i expect one of two available values (is / in) to be there:

"filters": [
    {
      "name": "value",
      "value": {
        ---> "type": "string", <---
        "value": "2"
      }
    }
  ]

I couldn't find any solution (annotation or wmth) which I can use to make openapi to make a correct property example of type. Expected to use some jackson annotation but found nothing about it...

How such a case can be handled?

0 Answers
Related