case class with field option[Int] is resolved as object and not Number
Hi, When I have something like this:
case class Test(quantity:Int, quantityOpt:Option[Int])
The swagger model will have this properties:
properties:
quantity:
type: integer
format: int32
quantityOpt:
type: object
But the right definition should be something like this
properties:
quantity:
type: integer
format: int32
quantityOpt:
type: integer
format: int32
@pjfanning , @fehguy
There are any solution for it ?
Thanks !
The current code uses Java reflection and suffers from type erasure - the model converter basically just gets notified that quantityOpt is an Option[Any].
You should be able to use swagger annotations on the quantityOpt field to fix your swagger doc. https://github.com/swagger-api/swagger-core/wiki/annotations-1.5.x
I added an example of how you can workaround this issue - https://github.com/pjfanning/swagger-akka-http-sample/commit/c2fa6004d3a14c7ecec6d469f1b171229ce69dcf
Thanks @pjfanning, using @ApiModelProperty works but let's hope it's a pain when you have a lot of classes.
Isn't it possible to fix without annotation? We are using external models. So its difficult to add annotations on every option field.
What is the solution to this using OpenAPI V3.0? Option[Int] still doesn't work in latest version
@GMTurbo https://github.com/swagger-api/swagger-scala-module/issues/55#issuecomment-399596128 -- this is still the case
so i'm not sure what annotation to use to modify the quantityOpt field. I have a bunch of case classes that have a lot of Options in them.
Because I'm using OpenAPI V3.0, i don't have access to the @ApiModelProperty annotation, so i'm supposed to use @Schema now but i'm not sure how to get it to work.
I've tried the following:
case class Metrics(id: String,
@(Schema @field)(`type` = "int") size: Option[Int] = None,
This doesn't seem to work although it compiles fine. Any ideas?
If you need OpenAPI 3, then you could try https://github.com/swagger-akka-http/swagger-scala-module - https://github.com/swagger-api/swagger-scala-module only supports swagger 2 spec.
Ok, so i got this working using the following:
case class Metrics(id: String,
@(Schema @field)(implementation = classOf[Int]) size: Option[Int] = None
Thanks