OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] Java code generator creates nonsense comparisons

Open
#17,620 0 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

Description

Look at the samples: https://github.com/OpenAPITools/openapi-generator/blob/13edc5d494c23cab6f90f58685746ea27d206afc/samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/Mammal.java#L104

This is meaningless nonsense:

                        attemptParsing |= ((Pig.class.equals(Integer.class) || Pig.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT);
                        attemptParsing |= ((Pig.class.equals(Float.class) || Pig.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT);
                        attemptParsing |= (Pig.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE));
                        attemptParsing |= (Pig.class.equals(String.class) && token == JsonToken.VALUE_STRING);

It is impossible for code like Pig.class.equals(Integer.class) to return anything but false.

openapi-generator version

7.2.0

OpenAPI declaration file content or url

https://github.com/OpenAPITools/openapi-generator/blob/13edc5d494c23cab6f90f58685746ea27d206afc/samples/client/petstore/java/native/api/openapi.yaml

Steps to reproduce

Run the javascript generator on the petstore sample.

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 with the generated sample at samples/client/petstore/java/native/src/main/java/org/openapitools/client/model/Mammal.java around line 104 and the linked samples/client/petstore/java/native/api/openapi.yaml. Reproduce the output by running the JavaScript generator on the petstore sample, then trace the Java generator source or templates responsible for these comparisons. Done means the generated Java code no longer contains the meaningless class comparisons and the sample output remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, javascript, openapi
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.