OpenAPITools / OpenAPITools/openapi-generator

[BUG] OpenAPI 3.1 component not matched correctly when using $ref

Open
#21,535 2 comments 2 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?
  • 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 generating an OpenAPI 3.1 spec using generator openapi-yaml or the spring generator (and maybe others). If a response schema uses a $ref to a component and that is also a $ref to another file, an inner schema reference will create a new component schema instead of re-using an existing one. If the response $ref links to a component that is defined within the root openapi.yaml (that still uses a $ref for inner schema) then the expected output of re-using the component is what happens.

I've also prepared an example using OpenAPI 3.0 with the same schema layout as the OpenAPI 3.1 bug version and it produces the expected output as well.

openapi-generator version

7.14.0

OpenAPI declaration file content or url

Repo: https://github.com/rockinrimmer/OpenAPI-Generator-Inline-Ref-Bug with more details of each version provided in the readme.

Generation Details
Steps to reproduce

See https://github.com/rockinrimmer/OpenAPI-Generator-Inline-Ref-Bug?tab=readme-ov-file#running

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

Start with the linked OpenAPI-Generator-Inline-Ref-Bug repository and follow its README running instructions to compare the OpenAPI 3.0 and 3.1 cases. Trace how the openapi-yaml and spring generators resolve component and inner $ref values; done means the OpenAPI 3.1 output reuses the existing component instead of creating a duplicate schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.