question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inherited properties are duplicated

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dilipkrishcommented, Aug 6, 2019

@bob-walters absolutely!

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

1reaction
severinstamplercommented, Mar 14, 2019

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…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid duplicate actions for base class properties
Create a function to check for base type errors and call that function inside other two types. Something like:
Read more >
Inheritance is a hammer. Eliminating code duplication is not a ...
I'm telling you that inheritance is one tool in your toolbelt, and it has its uses. But it isn't the right tool for...
Read more >
Duplicate inherited attributes during Hybris5 migration
Hello, I'm working on the migration of an Hybris 4.8 to an Hybris 5.0 Shop. In the old shop the type AbstractPage is...
Read more >
About the Duplicate Properties wizard - Pega Community
As a best practice for runtime performance, avoid having multiple properties in one class inheritance chain that have the same Property Name key...
Read more >
Acquiring Duplicate Documents of your Inherited Property
Services. Acquiring Duplicate Documents of Your Inherited Property. Ancestral Real Estate & Inheritance Advisory · Apostilization & Attestation of Documents ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found