0

I have this case class that's extending an abstract 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]
                    )

Exciting stuff, right? My problem is that the definition in the generated swagger.json file looks like this:

"OfferPrice": {
  "properties": {

  }
}

It's not including the fields from the abstract class. How can I include those fields as well?

L42
  • 3,052
  • 4
  • 28
  • 49

1 Answers1

1

It wouldn't work because fields and annotations declared in the super class are hidden by fields overridden in the subclass.

I think this is correct definition of your model:

@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]
)

but description of model and properties is not rendered in Scalatra's Swagger 2.0 support currently. It will be supported in the future release. See: https://github.com/scalatra/scalatra/issues/684

Naoki Takezoe
  • 471
  • 2
  • 7
  • Thank you for the help on Gitter! Could you edit your post here to include the solution? Then I'll accept the answer :) – L42 Jul 06 '17 at 06:48