swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Options and other containers do not work with boxed types

Open gorgonblot opened this issue 12 years ago • 1 comments

Creating this issue in swagger-core based on related issue previously raised on spray-swagger (https://github.com/gettyimages/spray-swagger/issues/31).

Consider the Scala example: @ApiModel(description = "Options of boxed types produces an Object ref instead of correct type") case class BoxedTypesIssue31(stringSeq: Seq[String], stringOpt: Option[String], @(ApiModelProperty @field)(value = "Integers in a Sequence Box") intSeq: Seq[Int], @(ApiModelProperty @field)(value = "Integer in an Option Box") intOpt: Option[Int], justInt: Int)

Using swagger-core to generate the Swagger Spec results in:

{ "description": "Options of boxed types produces an Object ref instead of correct type", "id": "BoxedTypesIssue31", "properties": { "intOpt": { "$ref": "Object", "description": "Integer in an Option Box" }, "intSeq": { "description": "Integers in a Sequence Box", "items": { "$ref": "Object" }, "type": "array" }, "justInt": { "format": "int32", "type": "integer" }, "stringOpt": { "type": "string" }, "stringSeq": { "items": { "type": "string" }, "type": "array" } } }

The attributes justInt, stringOpt, and stringSeq are represented as desired.

The attributes intOpt and IntSeq are not. The boxed value is indicated as "$ref": "Object" instead of "type":"integer".

The desired Swagger Spec is:

{ "description": "Options of boxed types produces an Object ref instead of correct type, but can be overcome with dataType", "id": "BoxedTypesIssue31WithDataType", "properties": { "intOpt": { "description": "Integer in an Option Box", "format": "int32", "type": "integer" }, "intSeq": { "description": "Integers in a Sequence Box", "items": { "format": "int32", "type": "integer" }, "type": "array" }, "justInt": { "format": "int32", "type": "integer" }, "stringOpt": { "type": "string" }, "stringSeq": { "items": { "type": "string" }, "type": "array" } } }

I have some code that I will submit as a pull request that resolves this issue (to my satisfaction).

gorgonblot avatar Nov 13 '14 15:11 gorgonblot

closing as PRs have been merged

fehguy avatar Nov 27 '14 23:11 fehguy