OpenAPITools / OpenAPITools/openapi-generator
[BUG] Inline schema overrides explicit schema with same name
Nobody has claimed this yet.
- 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?
Description
When an inline schema is generated which happens to have the same automatically chosen title as an explicitly-defined schema, the explicitly-defined schema is overridden and not included in the generated code. E.g. in the example below the explicit schema FirstSecond is not included in the generated code in any of the languages I tested (ruby, typescript, rust) but the inferred schema for First.second is included.
When deliberately giving two schemas the same title the generated code is named with a numerical suffix - ideally this behaviour could also be applied here, so the explicit schema is generated as FirstSecond and the implicit one as FirstSecond1.
openapi-generator version
7.14.0 (also tested on latest master)
OpenAPI declaration file content or url
---
openapi: 3.1.0
info:
title: Bug reproduction
version: 1.0.0
components:
schemas:
first:
type: object
title: First
properties:
second:
type: object
properties:
something:
type: string
first-second:
type: object
title: FirstSecond
properties:
anything:
type: number
Generation Details
openapi-generator-cli generate -i test.yaml -g ruby -o tmp/test-rb/
Steps to reproduce
- Run the CLI command above
- Open
tmp/test-rbin your favourite editor - Observe that
first_second.rbhas asomethingfield rather than ananythingone - Observe that only two schemas have been generated, rather than 3.
Related issues/PRs
I couldn't find any with a cursory search, though it was hard to know exactly what to look for.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided OpenAPI YAML and run the shown openapi-generator-cli command for Ruby, then trace the schema naming and collision handling used during generation. Done means the explicit FirstSecond schema is retained, the inline schema receives a distinct name, and all three schemas are generated without regressing the existing numerical-suffix behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100