Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3523
Closed
Open
Issue created Aug 01, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][JAVA] Generator does not generate inheritance when first element of allOf is not a ref

Created by: Arbuste

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

When declaring a schema as a composition of classes using allOf, having the first element of the allOf (which is meant to be the main inherited class extended in my Java subclass) not being a reference to a pre-existing class, it is simply ignored by the generator.

openapi-generator version

Swagger-editor and openapi-codegen 4.1.0

OpenAPI declaration file content or url
  schemas:
    Example1:
      type: object
      properties:
        Example1Property:
          type: string
    Example2:
      allOf:
        - type: object
          properties:
            Example2Property:
              type: string
        - $ref: '#/components/schemas/Example1'

The Swagger-editor generated Example2 class writes:

@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2019-08-01T11:15:04.683Z[GMT]")
public class Example2 implements  Example1 {
  @SerializedName("Example1Property")
  private String example1Property = null;

  public Example2 example1Property(String example1Property) {
    this.example1Property = example1Property;
    return this;
  }

   /**
   * Get example1Property
   * @return example1Property
  **/
  @Schema(description = "")
  public String getExample1Property() {
    return example1Property;
  }

  public void setExample1Property(String example1Property) {
    this.example1Property = example1Property;
  }

// all the usual methods...

The openapi-codegen generated Example2 class writes:

@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2019-08-02T09:54:03.694+02:00[Europe/Paris]")public class Example2 {

  @JsonProperty("Example1Property")

  private String example1Property = null;
  public Example2 example1Property(String example1Property) {
    this.example1Property = example1Property;
    return this;
  }

  

  /**
  * Get example1Property
  * @return example1Property
  **/
  @Schema(description = "")
  public String getExample1Property() {
    return example1Property;
  }
  public void setExample1Property(String example1Property) {
    this.example1Property = example1Property;
  }

// all the usual methods...

Expected output would have been (from openapi-codegen):

@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.JavaClientCodegen", date = "2019-08-02T09:54:03.694+02:00[Europe/Paris]")public class Example2 {

  @JsonProperty("Example2Property")
  @JsonProperty("Example1Property")

  private String example2Property = null;
  private String example1Property = null;

// ...
Command line used for generation

"C:\Program Files\Java\jdk1.8.0_72\bin\java" -jar swagger-codegen-cli.jar generate -i myDefs.yml -l java --library resttemplate -DsupportJava6=true -DdateLibrary=legacy -o out2/myproject --api-package com.my.project.client.api --model-package com.my.project.client.model -DhideGenerationTimestamp=true -DdisableApiModelAnnotations=true

Suggest a fix

Having the same behaviour as when the non pre-existing class is set as more than the first occurrence in the allOf and is generated as an interface, that is copying the attributes of the non pre-existing class in the subclass.

Assignee
Assign to
Time tracking