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] Upgrading to 3.1 breaks sharing types between APIs #20722

Open
4 of 6 tasks
david0 opened this issue Feb 24, 2025 · 0 comments
Open
4 of 6 tasks

[BUG] Upgrading to 3.1 breaks sharing types between APIs #20722

david0 opened this issue Feb 24, 2025 · 0 comments

Comments

@david0
Copy link

david0 commented Feb 24, 2025

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

When updating a specs from OpenAPI 3.0 to OpenAPI 3.1, types cannot be shared anymore, as two unrelated types are generated.

openapi-generator version

7.11.0

Steps to reproduce

Given these files:

foo.yaml

openapi: 3.0.4
info:
  title: foo API
  version: 0.0.1
paths:
  /foo:
    get:
      responses:
        200:
          description: foo
          content:
            application/json:
              schema:
                $ref: 'user.yml#/Response'

bar.yaml

openapi: 3.0.4
info:
  title: bar API
  version: 0.0.1
paths:
  /bar:
    get:
      responses:
        200:
          description: bar
          content:
            application/json:
              schema:
                $ref: 'user.yml#/Response'

and the shared common.yaml

Response:
  properties:
    id:
      type: integer

Running this will generate two files, one being the shared class:

for f in foo.yaml bar.yaml; do openapi-generator generate -g java -i $f; done

tree src/main/java/org/openapitools/client/model
src/main/java/org/openapitools/client/model
├── AbstractOpenApiSchema.java
└── Response.java

But if you change these files to openapi: 3.1.0, each API will have its own class:

src/main/java/org/openapitools/client/model
├── AbstractOpenApiSchema.java
├── BarGet200Response.java
└── FooGet200Response.java

This will make re-using code very hard. What is the recommended way to share types (classes) between APIs?

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