Swagger 将 Option[Int] 建模为 Object,而 Option[String] 被正确建模为字符串
Swagger models Option[Int] to Object while Option[String] is modelled correctly as string
我有以下情况class
@ApiModel("StationResponse") case class StationResponse (id: Option[String],
@ApiModelProperty(dataType = "double", required = false)
longitude: Option[Double])
经度字段建模为 "Object" 而不是 "double"
我尝试用@ApiModelProperty 覆盖数据类型,但没有成功。感谢您的评论。
我正在使用 Swagger 1.3.12 和 Scala 2.11.6
我通过添加 @field 注释和 ApiModelProperty 解决了这个问题,如下所示:
@ApiModel("StationResponse")
case class StationResponse (id: Option[String],
@(ApiModelProperty@field)(dataType = "double", required = false)
longitude: Option[Double])
我觉得现在有点简单了:
@ApiModelProperty(dataType = "Long") timingId: Option[Long]
对我来说效果很好:"io.swagger" %% "swagger-play2" % "1.6.0"
如果您使用的是 Springfox - 根据 documentation 您可以执行以下操作:
@ApiModel("StationResponse")
case class StationResponse (id: Option[String], longitude: Option[Double]) {
@ApiModelProperty(dataType = "double", required = false)
def getLongitude: Option[Double] = longitude
}
在其他 Swagger 生成库上可能值得一试
我有以下情况class
@ApiModel("StationResponse") case class StationResponse (id: Option[String],
@ApiModelProperty(dataType = "double", required = false)
longitude: Option[Double])
经度字段建模为 "Object" 而不是 "double"
我尝试用@ApiModelProperty 覆盖数据类型,但没有成功。感谢您的评论。
我正在使用 Swagger 1.3.12 和 Scala 2.11.6
我通过添加 @field 注释和 ApiModelProperty 解决了这个问题,如下所示:
@ApiModel("StationResponse")
case class StationResponse (id: Option[String],
@(ApiModelProperty@field)(dataType = "double", required = false)
longitude: Option[Double])
我觉得现在有点简单了:
@ApiModelProperty(dataType = "Long") timingId: Option[Long]
对我来说效果很好:"io.swagger" %% "swagger-play2" % "1.6.0"
如果您使用的是 Springfox - 根据 documentation 您可以执行以下操作:
@ApiModel("StationResponse")
case class StationResponse (id: Option[String], longitude: Option[Double]) {
@ApiModelProperty(dataType = "double", required = false)
def getLongitude: Option[Double] = longitude
}
在其他 Swagger 生成库上可能值得一试