Subtypes not added recursively
If an API directly references a Model with subTypes, both the referenced Model and its subTypes are added to the Swagger Spec. However, if the API references a Model that has a field that is of a Model type that has subTypes, the subTypes are not added to the spec. The desired behavior is for subTypes to be added in recursively when finding all of the model dependencies.
For example, an API referencing the "ModelWithFieldWithSubTypes" should result in all 4 Models being defined in the spec:
- ModelWithFieldWithSubTypes
- AbstractBaseModelWithSubTypes
- Thing1
- Thing2
@ApiModel(description = "Class that has a field that is the AbstractBaseModelWithSubTypes") case class ModelWithFieldWithSubTypes( @(ApiModelProperty @field)(value = "Contained field with sub-types") z: AbstractBaseModelWithSubTypes)
@ApiModel(description = "I am an Abstract Base Model with Sub-Types", discriminator = "_type", subTypes = Array(classOf[Thing1], classOf[Thing2])) trait AbstractBaseModelWithSubTypes { @(ApiModelProperty @getter)(value = "This value is used as a discriminator for serialization") val _type: String @(ApiModelProperty @getter)(value = "An arbitrary field") val a: String @(ApiModelProperty @getter)(value = "An arbitrary field") val b: String }
@ApiModel(description = "Shake hands with Thing1", parent = classOf[AbstractBaseModelWithSubTypes]) case class Thing1( @(ApiModelProperty @field)(value = "Override the abstract a") a: String, @(ApiModelProperty @field)(value = "Thing1 has an additional field") x: Int) extends AbstractBaseModelWithSubTypes { val _type = "Thing1" val b = "bThing" }
@ApiModel(description = "and Thing2", parent = classOf[AbstractBaseModelWithSubTypes]) case class Thing2( @(ApiModelProperty @field)(value = "Override the abstract a") a: String, @(ApiModelProperty @field)(value = "Thing2 has an additional field") s: String) extends AbstractBaseModelWithSubTypes { val _type = "Thing2" val b = "bThing" }
Hi, to set timing expectations, the subtype support is being addressed in the 1.5-M2 release:
https://github.com/swagger-api/swagger-core/milestones
So it is expected that it doesn't work right now. I do appreciate the test cases though, and we'll bake those into the unit tests when we build it out.
The problem has been eliminated in fix for #847, here's a test confirming this: https://github.com/MDoumin/swagger-core/commit/cfe4e7b2aa998cb4da9fde6ec80ce009188d5009
Fixed in develop_2.0.