OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java] Model does not compile due to fluent-setters conflicting with `set_*` field normal setter

Open
#14,770 8 comments 5 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

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 npx package
Steps to reproduce
  1. Run on the command-line:
npx @openapitools/openapi-generator-cli generate -g java -i https://gist.githubusercontent.com/magicDGS/98af9201ab588491fdc6a9d798e62713/raw/39ae21c701334aa9b4fcb04dc32094314f81924d/openapi.yaml
  1. Check the class org.openapitools.client.model.ConflictingSchema
  2. Class does not compile due to the following methods:
    imagen
Related issues/PRs
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.