OpenAPITools / OpenAPITools/openapi-generator

[BUG] Duplicate methods/fields generated

Open
#12,187 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Duplicate fields and methods are being generated when generating JAX-RS spec server

When generating Java server code using the jaxrs-spec generator, model classes are generated with duplicate fields, methods, constructors, etc. I'm not positive, but I believe it may be due to the fact that the OpenAPI spec I'm generating off of contains $ref declarations.

openapi-generator version

5.4.0

OpenAPI declaration file content or url

The OpenAPI spec in question is here:

https://github.com/TheGeekPharaoh/asc4j/blob/main/src/main/resources/enhanced_app_store_connect_api_1.8_openapi.json

Generation Details

openapi-generator generate -i openapi.json
--api-package net.odyssi.asc4j.jaxrs
-g jaxrs-spec
--model-package net.odyssi.asc4j.model
--additional-properties=booleanGetterPrefix=is,dateLibrary=java8,openApiNullable=false,serializableModel=true,hideGenerationTimestamp=true,generateBuilders=true,sourceFolder=src/main/java,interfaceOnly=true,useSwaggerAnnotations=false

Steps to reproduce

Running the above command generates the malformed Java output

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided openapi-generator command with the linked OpenAPI declaration and inspect the generated jaxrs-spec Java model classes. Trace how the referenced schemas produce fields, methods, and constructors, then verify that each generated member appears only once in the output.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.