OpenAPITools / OpenAPITools/openapi-generator

[BUG] Incorrect interpretation of yaml spec

Open
#13,780 1 comment 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

openapi-generator seems to interpret original yaml file incorrectly, therefore producing incorrect models.

Original yaml differs from one getting placed in api/ folder after generation. Generated file uses wrong schemas for $refs:

    Manage_CreateVpsResponse:
      example:
        vps: null
        error: null
      properties:
        vps:
          $ref: '#/components/schemas/Manage_AttachSshKeyResponse_vps'
        error:
          $ref: '#/components/schemas/Manage_CreateVpsResponse_error'
      type: object

# schema definition for clarity
----
    Manage_AttachSshKeyResponse_vps:
      allOf:
      - $ref: '#/components/schemas/Manage_VpsInfo'

Original yaml:

        Manage_CreateVpsResponse:
            type: object
            properties:
                vps:
                    allOf:
                        - $ref: '#/components/schemas/Manage_VpsInfo'
                error:
                    allOf:
                        - $ref: '#/components/schemas/Manage_CreateVpsResponse_Error'

Manage_VpsInfo is a common message that is being used between all other responses. Every object that has vps property should use this message's schema but instead it generates one inline schema object ManageAttachSshKeyResponse_vps and uses it throughout the spec file.

Unfortunately, I cannot provide steps for reproducing this issue since I have no idea in which cases it does manifest itself.
The only thing I've noticed is that the generator takes the first response object alphabetically that has vps property and proceeds to use it instead of valid ones.

openapi-generator version

openapi-generator-cli via latest-release tag from docker-hub

Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

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

Compare the original YAML with the generated file in the api/ folder, focusing on the $ref entries for Manage_CreateVpsResponse and Manage_VpsInfo. A useful resolution should preserve the original shared schema references rather than selecting an inline schema, but reproduction steps are still needed to define and verify the fix.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.