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][JAVA] Referenced components with same name not distinguished when one starts with lowercase #20814

Open
1 task
phlechev opened this issue Mar 6, 2025 · 0 comments

Comments

@phlechev
Copy link

phlechev commented Mar 6, 2025

Bug Report Checklist

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

The generator does not generate classes correctly when there are referenced components with the same name but one of them starts with lowercase and the other one with uppercase.

Here is an example

cat.yaml

schemas:
    Cat:
      type: object
      properties:
        age:
          type: integer
        color:
          type: string
        sound:
          $ref: '#/components/schemas/sound'

    sound:
      type: string
      enum: [MEOUW, MRRR]

dog.yaml

schemas:
    Dog:
      type: object
      properties:
        age:
          type: integer
        color:
          type: string
        sound:
          $ref: '#/components/schemas/Sound'

    Sound:
      type: string
      enum: [WOOF, RRRR]

pet-shop.yaml

paths:
  /cat/{catId}:
    get:
      operationId: getCat
      description: Gets a cat
      parameters:
        - in: path
          name: catId
          description: Id of the cat
          schema:
            type: integer
          required: true
      responses:
        '200':
          description: 'OK'
          content:
            application/json:
              schema:
                $ref: 'cat.yaml#/components/schemas/Cat'
 
  /dog/{dogId}:
    get:
      operationId: getDog
      description: Gets a dog
      parameters:
        - in: path
          name: dogId
          description: Id of the dog
          schema:
            type: integer
          required: true
      responses:
        '200':
          description: 'OK'
          content:
            application/json:
              schema:
                $ref: 'dog.yaml#/components/schemas/Dog'

When we run the generate-sources for pet-shop.yaml only one SoundDto.java enum is generated - the one that starts with lowercase and cosequently the DogDto contains an enum [MEOUW, MRRR].

If both enums are called Sound or sound, then the generator correctly generates two enums - SoundDto and Sound1Dto, but when one starts with lowercase and the other with uppercase, the lowercase takes precedence and as a result the Dog object gets an incorrect type for it's sound property.

The expected behavior is that the generator recognizes these are two different types and generates two different classes

openapi-generator version

7.11.0 but is also reproducible with earlier versions (6.6.0). Last known version that worked was 4.3.1 but there might be more versions that worked between 4.3.1 and 6.6.0

Steps to reproduce

Attached is the example project, it can be reproduced by running maven

pet-shop.zip

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

1 participant