springfox: Inherited properties are duplicated

The polymorphism implemented in PR #1152 seems to not work correctly. Properties defined in the parent type are also present in the subtype but according to the oas 3.0 spec only additional properties should be in the subtype.

@ApiModel(subTypes = {Car.class})
class Vehicle {
	private String make;
}

@ApiModel(parent = Vehicle.class)
class Car extends Vehicle {
	private int seatingCapacity;
}

actual output:

{
  "Car": {
    "title": "Car",
    "allOf": [
      {
        "$ref": "#/definitions/Vehicle"
      },
      {
        "type": "object",
        "properties": {
          "make": {
            "type": "string"
          },
          "seatingCapacity": {
            "type": "integer",
            "format": "int32"
          }
        },
        "title": "Car"
      }
    ]
  }
}

expected output (without make property inherited from vehicle):

{
  "Car": {
    "title": "Car",
    "allOf": [
      {
        "$ref": "#/definitions/Vehicle"
      },
      {
        "type": "object",
        "properties": {
          "seatingCapacity": {
            "type": "integer",
            "format": "int32"
          }
        },
        "title": "Car"
      }
    ]
  }
}

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

@bob-walters absolutely!

@cy-ddg There is a plan to do it as part of #3070

I’m facing the same problem. It’s a bit annoying, because swagger-codegen-cli for csharp creates deditcated properties in the derived model objects, which hide the same properties in the base object (which is wrong for obvious reasons), and the generated code can’t compile as it doesn’t initialize those properties in the base constructors of those objects. One could argue, that it’s a problem in swagger-codegen, however, I do also think that the properties shouldn’t be duplicated. by the way, using the swagger-maven-plugin to generate the api specification from the swagger annotations at compile time, those properties aren’t duplicated. (the maven plugin has different issues though that also create faulty api specs, but in a different way…)