OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java] Model does not compile due to fluent-setters conflicting with `set_*` field normal setter
Nobody has claimed this yet.
- 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
When trying to generate a default java client model for an API that I described (and where I have no control over the serialized model returned by it), the class generated for one schema contains duplicated methods and thus does not compile. The schema itself containing a name and a set_name fields. This results on 2 methods called setName, one being the builder-like setter for the set_name field and the other the setter for the name field.
I would like to know if this is something that can be fixed or there is already a workaround for this use-case. The only requirement is to be able to deserialize/serialize the object with the name and set_name field, so it doesn't matter if the way to do so is to change the field-name/methods on the generated class as a workaround.
openapi-generator version
6.3.0
OpenAPI declaration file content or url
Generation Details
- Generator:
java - Config: default
- Run with
npxpackage
Steps to reproduce
- Run on the command-line:
npx @openapitools/openapi-generator-cli generate -g java -i https://gist.githubusercontent.com/magicDGS/98af9201ab588491fdc6a9d798e62713/raw/39ae21c701334aa9b4fcb04dc32094314f81924d/openapi.yaml
- Check the class
org.openapitools.client.model.ConflictingSchema - Class does not compile due to the following methods:

Related issues/PRs
- https://github.com/OpenAPITools/openapi-generator/issues/9444 - similar problem, but without
set on the prefix, but just_(_typeandtype` conflicting).
Suggest a fix
The solution on the related issue won't work as only takes into account names starting with _.
As I am kind of new with OpenAPI and its generator, the only suggestion that I have is to provide a way to override the name of the field/getter/setter somehow for those kind of conflicting names, or adding some extension for providing it on the openapi spec.
If there is a generator and/or option of using a different library than GSON for the model serialization/deserialization, it is also a solution from my side, as I don't need to stick to a specific library.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided npx generation command with the linked OpenAPI declaration and inspect the generated org.openapitools.client.model.ConflictingSchema class. Compare the duplicate setName methods with the related issue #9444. Done means the generated Java model compiles while preserving serialization and deserialization for both name and set_name fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100