I have a couple enumerations in an annotated object like:
@Schema(description = "Request description")
case class Request(
@Schema(description = "Enum1 description")
field2: Enum1,
@Schema(description = "Enum2 description")
field2: Enum2
)
where the enums are defined as:
sealed trait Enum1 extends EnumEntry
object Enum1 extends Enum[Enum1] {
case object Value1 extends Enum1
case object Value2 extends Enum1
}
sealed trait Enum2 extends EnumEntry
object Enum2 extends Enum[Enum2] {
case object Value3 extends Enum2
case object Value4 extends Enum2
}
Using Openapi3, I can generate a swagger documentation. My problem is that say Enum1
and Enum2
are translated differently, as in:
"field1":{
"enum":["Value1","Value2"],
"type":"string"
},
"field2":{
"$ref":"#/components/schemas/Enum2"
}
/* ... */
"Enum2":{
"description":"Enum2 description",
"type":"object"
}
I want Enum2
to be documented the same as Enum1
, so with the actual enumeration values. Is there any way to force this, or any explanation on why this might happen? Two enumerations are basically the same as in the example.
CodePudding user response:
In my case, I managed to solve it by adding the implementation
argument to the @Schema
annotation. Based on this and this:
@Schema(description = "Request description")
case class Request(
@Schema(
implementation = classOf[Enum1],
description = "Enum1 description"
)
field1: Enum1,
)