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
  • #8948
Closed
Open
Issue created Mar 10, 2021 by Administrator@rootContributor

[Java] Bug - Doesn't generate correct classes for models with same nested properties

Created by: bcampolo

Description

When an inline model has two or more properties that are inline objects (not using $ref) and those objects have the same set of properties the generator combines them in to a single Java class and references that class for both children properties even though these objects may not be conceptually related at all (see YAML example below)

openapi-generator version

5.0.1

OpenAPI declaration file content or url
components:
  schemas:
    Receipt:
      type: object
      properties:
        Order:
          type: object
          properties:
            id:
              type: integer
              format: int64
            name:
              type: string
        Customer:
          type: object
          properties:
            id:
              type: integer
              format: int64
            name:
              type: string
Command line used for generation

generate -i -g java --additional-properties=withXml=false,java8=true,library=native,serializationLibrary=jackson,dateLibrary=java8,hideGenerationTimestamp=true -o ./client

Steps to reproduce

Run generator using the above command line on a YAML file that includes the above snippet and you will get code that looks like this for Receipt:

public class Receipt {
  @SerializedName("Order")
  private ReceiptOrder order = null;

  @SerializedName("Customer")
  private ReceiptOrder customer = null;

Note both the "order" property and the "customer" property are of type ReceiptOrder which while functional seems wrong or at the very least confusing to anyone using the client, especially for methods with signatures like: setCustomer(ReceiptOrder customer)

Related issues/PRs

Not for openapi-generator but in swagger-codegen: https://github.com/swagger-api/swagger-codegen/issues/4883

Suggest a fix/enhancement

I would assume the default would not combine objects and would only combine objects when a $ref was used explicitly. At the very least an option should be provided to turn this combining logic off.

Assignee
Assign to
Time tracking