Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Options and other containers don't work with boxed types #31

Open
ljwagerfield opened this issue Jul 21, 2014 · 9 comments
Open

Options and other containers don't work with boxed types #31

ljwagerfield opened this issue Jul 21, 2014 · 9 comments

Comments

@ljwagerfield
Copy link

Boxed types are treated as Object types when used as type parameters within Api Models.

For example, the following case class...

case class Foo(stringSeq: Seq[String], stringOpt: Option[String], intSeq: Seq[Int], intOpt: Option[Int])

... produces the following api-doc JSON snippet:

{
  "models": {
    "Foo": {
      "id": "Foo",
      "properties": {
        "stringSeq": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "stringOpt": {
          "type": "string"
        },
        "intSeq": {
          "type": "array",
          "items": {
            "$ref": "Object"
          }
        },
        "intOpt": {
          "$ref": "Object"
        }
      }
    }
  }
}

Notice how the type information for Int is lost but String remains.

@mhamrah
Copy link
Contributor

mhamrah commented Jul 21, 2014

What version are you using? We'll need to investigate since from 0.4
spray-swagger uses swagger-core for serialization, so I'll need to hunt
down where this is actually happening.

On Jul 21, 2014, at 6:47 AM, Lawrence Wagerfield [email protected]
wrote:

Boxed types are treated as Object types when used as type parameters within
Api Models.

For example, the following case class...

case class Foo(stringSeq: Seq[String], stringOpt: Option[String], intSeq:
Seq[Int], intOpt: Option[Int])

... produces the following api-doc JSON snippet:

{
"models": {
"Foo": {
"id": "Foo",
"properties": {
"stringSeq": {
"type": "array",
"items": {
"type": "string"
}
},
"stringOpt": {
"type": "string"
},
"intSeq": {
"type": "array",
"items": {
"$ref": "Object"
}
},
"intOpt": {
"$ref": "Object"
}
}
}
}
}

Notice how the type information for Int is lost but String remains.


Reply to this email directly or view it on GitHub
#31.

@ljwagerfield
Copy link
Author

Using 0.4.3

@mhamrah
Copy link
Contributor

mhamrah commented Oct 23, 2014

Sorry for the really late response on this. Did you try bumping to the latest version? 0.4 would be the closest backwards compatible one.

We were originally doing our own custom annotation parsing but since 0.4 we switch to swagger-core. This should more closely align with what swagger does. Let me know if that works and again, sorry for the delay.

@gorgonblot
Copy link

I have also reproduced this in version 0.4.6 (i.e., after the switch to use swagger-core).

"Foo" : {
"id" : "Foo",
"description" : "Options of boxed types produces an Object ref instead of correct type",
"properties" : {
"stringSeq" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"stringOpt" : {
"type" : "string"
},
"intSeq" : {
"type" : "array",
"items" : {
"$ref" : "Object"
}
},
"intOpt" : {
"$ref" : "Object"
}
}
},

@mhamrah
Copy link
Contributor

mhamrah commented Nov 8, 2014

Thanks for the follow up. We'll need to look into this and see what we can
do. Definitely annoying- I wonder how Play and Scalatra support deal with
it.

On Thursday, November 6, 2014, gorgonblot [email protected] wrote:

I have also reproduced this in version 0.4.6 (i.e., after the switch to
use swagger-core).

"Foo" : {
"id" : "Foo",
"description" : "Options of boxed types produces an Object ref instead of
correct type",
"properties" : {
"stringSeq" : {
"type" : "array",
"items" : {
"type" : "string"
}
},
"stringOpt" : {
"type" : "string"
},
"intSeq" : {
"type" : "array",
"items" : {
"$ref" : "Object"
}
},
"intOpt" : {
"$ref" : "Object"
}
}
},


Reply to this email directly or view it on GitHub
#31 (comment)
.

@gorgonblot
Copy link

I have created a BoxedTypesTest in Swagger-Core and made a modification that results in:

"intSeq" : {
"type" : "array",
"items" : {
"type" : "integer",
"format":"int32"
}
},
"intOpt" : {
"type" : "integer",
"format":"int32"
}

It requires specifying the dataType in the annotation. See the version of swagger-core at:

https://github.com/gorgonblot/swagger-core/tree/contrib/issue31

@mhamrah
Copy link
Contributor

mhamrah commented Nov 10, 2014

Very nice. Let's keep this open and I'll be sure to bump the core version when it's merged upstream.

@bthibault
Copy link

I'm dealing with this now .... I'm not exactly sure what the work around is here??

@Satyricon
Copy link

One workaround for Option[Int] case is using Option[Integer] instead.

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

No branches or pull requests

5 participants