OpenAPITools / OpenAPITools/openapi-generator

[BUG] Inline schema overrides explicit schema with same name

Open
#22,012 8 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

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
  1. Run the CLI command above
  2. Open tmp/test-rb in your favourite editor
  3. Observe that first_second.rb has a something field rather than an anything one
  4. 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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.