Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allOf Inheritance is broken in schema with more than two layers hierarchy #4423

Closed
6 tasks
globalstick opened this issue Nov 8, 2019 · 4 comments · Fixed by #4503
Closed
6 tasks

allOf Inheritance is broken in schema with more than two layers hierarchy #4423

globalstick opened this issue Nov 8, 2019 · 4 comments · Fixed by #4503
Milestone

Comments

@globalstick
Copy link

globalstick commented Nov 8, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

In schema hierarchy with more, than two layers by Code Generation all classes in parent classes tree are merged within child class.

For example, if you try to generate a model classes from SchemaC, which allOfs SchemaB (with discrimanator), and SchemaB (with discrimanator) allofs SchemaA (with discrimanator), you will get Java class SchemaC, which contains all attributes of SchemaC, SchemaB and SchemaA instead of extending class SchemaB. SchemaC does not extend any class at all. Could you please solve this issue. Some example code is down there (without root yaml file)

openapi-generator version

4.4.2

OpenAPI declaration file content or url
roxspring added a commit to roxspring/openapi-generator that referenced this issue Nov 8, 2019
@roxspring
Copy link
Contributor

roxspring commented Nov 8, 2019

After attempting a migration from swagger-codegen 2.x I hit this yesterday morning and have been scratching my head ever since. I concluded that its a bug worth reporting and discovered that one was raised just 2h earlier!

Applying the problem to the petstore examples, I created a BigCat definition extending Cat which extends Animal (without bothering with an additional discriminator, but valid according to https://apitools.dev/swagger-parser/online/), and ran ./bin/springboot-petstore-server.sh:

...
  BigCat:
    allOf:
      - $ref: '#/definitions/Cat'
      - type: object
        properties:
          kind:
            type: string
            enum: [lions, tigers, leopards, jaguars]
...

Under swagger-codegen 2.3.1, 2.4.9, Animal is annotated:

@JsonSubTypes({
  @JsonSubTypes.Type(value = BigCat.class, name = "BigCat"),
  @JsonSubTypes.Type(value = Dog.class, name = "Dog"),
  @JsonSubTypes.Type(value = Cat.class, name = "Cat"),
})

and BigCat is defined:

public class BigCat extends Cat  {
  /**
   * Gets or Sets kind
   */
  public enum KindEnum {
    LIONS("lions"),    
    TIGERS("tigers"),    
    LEOPARDS("leopards"),    
    JAGUARS("jaguars");
...

Whereas under openapi-generator (master) Animal annotations know nothing of BigCat:

@JsonSubTypes({
  @JsonSubTypes.Type(value = Dog.class, name = "Dog"),
  @JsonSubTypes.Type(value = Cat.class, name = "Cat"),
})

and BigCat is defined without reference to Cat and copying all the fields instead:

public class BigCat   {
  @JsonProperty("className")
  private String className;

  @JsonProperty("color")
  private String color = "red";

  @JsonProperty("declawed")
  private Boolean declawed;
...

Not sure whether this ever worked in openapi-generator but it's certainly a regression since forking.

Also odd: openapi-generator generates additional DogAllOf, CatAllOf, BigCatAllOf seemingly coming from the composite schemas. Maybe this is unrelated and the new normal but it's really weird.

@roxspring
Copy link
Contributor

... and researching further it appears this might be the same as previously reported variants:

None of these seem to have any activity or even acknowledgement 😞. Is there any chance of this regression being addressed @wing328? Or can somebody offer guidance or some starting points on what the fix might be?

@cvgaviao
Copy link

cvgaviao commented Dec 9, 2019

@wing328, could you please take a look on this issue and the provided PR?

@jimschubert
Copy link
Member

Fixed by #4503 please evaluate and let us know if it needs to be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants