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

[BUG] Generating java code results in double models model.java, model1.java etc. #20454

Open
RonaldAtGitHub opened this issue Jan 13, 2025 · 4 comments

Comments

@RonaldAtGitHub
Copy link

Description

In our contract, we use $ref to point to shared models. If we use openapi:3.1.0 then it gives duplicate models in the java code we generate. For example, we have a Client.java and a Client1.java.

We have found that if we use $ref along with allOf: that we do not get duplicate models.

Is this a bug and is our use of allOf a correct solution?

openapi-generator version

We are using the npm wrapper "@openapitools/openapi-generator-cli": "^2.15.3".
I think this defaults to the latest version.

OpenAPI declaration file content or url

This results in Office.java and Office1.java
`type: object
title: IdentifiedClientOrRelation
properties:
id:
type: string
number:
type: string
name:
type: string
office:
$ref: '../../../openapi.yml#/components/schemas/Office'
required:

  • id
  • number
  • name
    `

But this results in only Office.java

`type: object
title: IdentifiedClientOrRelation
properties:
id:
type: string
number:
type: string
name:
type: string
office:
allOf:
- $ref: '../../../openapi.yml#/components/schemas/Office'
required:

  • id
  • number
  • name
    `
Generation Details

package.json
{ "name": "e2e", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "generate:server": "openapi-generator-cli generate -c generated-server-code/config.json" }, "author": "", "license": "ISC", "dependencies": { "@openapitools/openapi-generator-cli": "^2.15.3", "mustache": "^4.2.0" }, "devDependencies": { "rimraf": "^6.0.1" } }

Steps to reproduce

npm run generate:server

Related issues/PRs
Suggest a fix
@wing328
Copy link
Member

wing328 commented Jan 14, 2025

can you please share a spec (properly formatted) via gist.github.com for example so that we can take a look?

@RonaldAtGitHub
Copy link
Author

Hi,

I have create a repo with the setup and working code.

https://github.com/RonaldAtGitHub/openapi-generator

hopefully it is clear

@danish-kamal-sophos
Copy link

I am also facing the same issue with v 6.3.0 of the openapi-generator-gradle-plugin for Spring

@danish-kamal-sophos
Copy link

I was able to fix the issue by removing a cycle in my schemas: one of the nested schema was referring to another type outside. And the outside type was referring to another schema inside. I moved the outside schema to inside directory which fixed the issue for me.

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

No branches or pull requests

3 participants