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

Support Scala Enumeration Types #760

Closed
gorgonblot opened this issue Nov 19, 2014 · 1 comment
Closed

Support Scala Enumeration Types #760

gorgonblot opened this issue Nov 19, 2014 · 1 comment

Comments

@gorgonblot
Copy link

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:

  • 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")
case class SModelWithEnum(
                     @(ApiModelProperty @field)(value = "Textual label") label: Option[String],
                     @(ApiModelProperty @field)(value = "Order Size") orderSize: OrderSize )

case object OrderSize extends Enumeration(0) {
  type OrderSize = Value
  val TALL = Value("TALL")
  val GRANDE = Value("GRANDE")
  val VENTI = Value("VENTI")
}

Currently, the Swagger Spec 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 Swagger Spec 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:

@(ApiModelProperty @field)(value = "Order Size", dataType = "models.OrderSize$") orderSize

I will submit a pull request demonstrating this support.

@fehguy
Copy link
Contributor

fehguy commented Dec 20, 2014

closing as #761 has been merged

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

No branches or pull requests

2 participants