Skip to content

Subtypes not added recursively #852

@gorgonblot

Description

@gorgonblot

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"
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions