OpenAPITools / OpenAPITools/openapi-generator

[BUG] Unable to generate shared external reference DTOs for open API 3.1

Open
#18,361 18 comments 1 reaction 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

Description

I try to move from openapi 3.0.3 to 3.1, but I have a strange behaviour with ref schema.
With 3.0.3 ref schemas are generated (java/spring) with a dedicated Dto, example a schema common.Amount creates a Dto CommonAmount that use as is from all the places.
With 3.1 it now creates a new schema for all the places it’s used.
It’s not related to the generator, but to the parsing: It changed in file OpenAPIV3Parser, L211 if (result.getOpenAPI().getOpenapi() != null && result.getOpenAPI().getOpenapi().startsWith("3.1")) {

I had a maven/springboot project to reproduce it: https://github.com/pkernevez/pb-openapi
The only difference in swaggers “3.0” and “3.1" are the version in the first line.
In my example, I have a share type : common.Amount (a quantity and a currency).
With 3.0.3 I have a shared type CommonAmount, with 3.1 I now have a new type for each usage (here market value).
Why this behaviour changed ?
Is there a way to restore the previous way ?

Having a new class for each usage is an issue to define only once shared code, like mapping Entity <-> Dto

image

openapi-generator version

Tested with :

  • 7.4.0
  • 7.5.0-SNAPSHOT on April 11th.
OpenAPI declaration file content or url
Generation Details

APIs are the same, the issues is for Dtos.

image
Steps to reproduce
mvn clean install
find target/generated-sources/src/main/java/net/kernevez/generated

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

Reproduce the difference with the linked pb-openapi Maven project and compare the generated DTOs for its OpenAPI 3.0.3 and 3.1 files. Then inspect OpenAPIV3Parser around line 211, where the 3.1 path is selected. Done means determining why shared external references produce per-use schemas and restoring shared DTO generation without changing the intended 3.1 parsing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring-boot
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.