如何在生成的 Swagger 规范中包含来自超类的字段(使用 Scalatra+Swagger)?
How can I include fields from a superclass in the generated Swagger spec (using Scalatra+Swagger)?
我有这个案例 class 扩展了一个抽象 class:
@ApiModel(description = "A price for an offer.")
case class OfferPrice(
override val amount: Double,
override val taxAmount: Double,
override val taxRate: Option[Double]
) extends Price(amount, taxAmount, taxRate)
abstract class Price(
@(ApiModelProperty@field)(description = "The amount.") val amount: Double,
@(ApiModelProperty@field)(description = "The tax amount.") val taxAmount: Double,
@(ApiModelProperty@field)(description = "The tax rate.") val taxRate: Option[Double]
)
令人兴奋的东西,对吧?我的问题是生成的 swagger.json 文件中的定义如下所示:
"OfferPrice": {
"properties": {
}
}
它不包括摘要中的字段 class。我怎样才能同时包含这些字段?
它不会工作,因为在超级 class 中声明的字段和注释被子 class 中覆盖的字段隐藏。
我认为这是您模型的正确定义:
@ApiModel(description = "A price for an offer.")
case class OfferPrice(
@ApiModelProperty(description = "The amount.") amount: Double,
@ApiModelProperty(description = "The tax amount.") taxAmount: Double,
@ApiModelProperty(description = "The tax rate.") taxRate: Option[Double]
) extends Price(amount, taxAmount, taxRate)
abstract class Price(
amount: Double,
taxAmount: Double,
taxRate: Option[Double]
)
但是 Scalatra 的 Swagger 2.0 支持目前没有呈现模型和属性的描述。它将在未来的版本中得到支持。参见:https://github.com/scalatra/scalatra/issues/684
我有这个案例 class 扩展了一个抽象 class:
@ApiModel(description = "A price for an offer.")
case class OfferPrice(
override val amount: Double,
override val taxAmount: Double,
override val taxRate: Option[Double]
) extends Price(amount, taxAmount, taxRate)
abstract class Price(
@(ApiModelProperty@field)(description = "The amount.") val amount: Double,
@(ApiModelProperty@field)(description = "The tax amount.") val taxAmount: Double,
@(ApiModelProperty@field)(description = "The tax rate.") val taxRate: Option[Double]
)
令人兴奋的东西,对吧?我的问题是生成的 swagger.json 文件中的定义如下所示:
"OfferPrice": {
"properties": {
}
}
它不包括摘要中的字段 class。我怎样才能同时包含这些字段?
它不会工作,因为在超级 class 中声明的字段和注释被子 class 中覆盖的字段隐藏。
我认为这是您模型的正确定义:
@ApiModel(description = "A price for an offer.")
case class OfferPrice(
@ApiModelProperty(description = "The amount.") amount: Double,
@ApiModelProperty(description = "The tax amount.") taxAmount: Double,
@ApiModelProperty(description = "The tax rate.") taxRate: Option[Double]
) extends Price(amount, taxAmount, taxRate)
abstract class Price(
amount: Double,
taxAmount: Double,
taxRate: Option[Double]
)
但是 Scalatra 的 Swagger 2.0 支持目前没有呈现模型和属性的描述。它将在未来的版本中得到支持。参见:https://github.com/scalatra/scalatra/issues/684