You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ApiModel generated from a Scala class with a field that is an Enumeration Value has two problems:
The type is shown as a $ref: Value
The set of values in the Enumeration are not used to set the allowableValues or enums in the Swagger spec.
Take for example the case class and Enumeration example below:
@ApiModel(description ="Scala model containing an Enumeration Value that is annotated with the dataType of the Enumeration class")
caseclassSModelWithEnum(
@(ApiModelProperty@field)(value ="Textual label") label: Option[String],
@(ApiModelProperty@field)(value ="Order Size") orderSize: OrderSize )
caseobjectOrderSizeextendsEnumeration(0) {
typeOrderSize=ValuevalTALL=Value("TALL")
valGRANDE=Value("GRANDE")
valVENTI=Value("VENTI")
}
Currently, the SwaggerSpec is generated as:
{
"description":"Scala model containing an Enumeration Value",
"id":"SModelWithEnum",
"properties": {
"label": {
"description":"Textual label",
"type":"string"
},
"orderSize": {
"$ref":"Value",
"description":"Order Size"
}
}
}
The desired behavior is to generate the SwaggerSpec as below:
{
"id":"SModelWithEnum",
"description":"Scala model containing an Enumeration Value",
"properties": {
"label": {
"type":"string",
"description":"Textual label"
},
"orderSize": {
"type":"string",
"description":"Order Size",
"enum": ["GRANDE","TALL","VENTI"]
}
}
}
Using reflection alone, I don't think it is possible to know that the Enumeration Value is a member of the specific Enumeration object. However, with an additional dataType annotation on the field, the desired Swagger Spec can be generated. For example:
This is related to spray-swagger Issue #1 (gettyimages/spray-swagger#1)
The ApiModel generated from a Scala class with a field that is an Enumeration Value has two problems:
Take for example the case class and Enumeration example below:
Using reflection alone, I don't think it is possible to know that the Enumeration Value is a member of the specific Enumeration object. However, with an additional dataType annotation on the field, the desired Swagger Spec can be generated. For example:
@(ApiModelProperty @field)(value = "Order Size", dataType = "models.OrderSize$") orderSize
I will submit a pull request demonstrating this support.
The text was updated successfully, but these errors were encountered: