[BUG] [JAVA] openapi-generator-maven-plugin does not handle allOf composed of multiple objects
See original GitHub issueBug 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
Using allOf
composed of multiple objects in a response does not generate a class combining these multiple objects. Instead it uses the first class defined in the allOf
section.
openapi-generator version
Version 5.2.0
:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.2.0</version>
</plugin>
I have also tested with master
(5.2.1-SNAPSHOT
), commit fe9636e9.
OpenAPI declaration file content or url
Important part here is the allOf
:
openapi: 3.0.0
info:
title: Test
version: v1
paths:
/test:
get:
operationId: get
responses:
'200':
description: Get
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/A'
- $ref: '#/components/schemas/B'
components:
schemas:
A:
type: object
properties:
attA:
type: string
B:
type: object
properties:
attB:
type: integer
Generation Details
generatorName: java
inputSpec: openapi.yaml
Steps to reproduce
mvn org.openapitools:openapi-generator-maven-plugin:5.2.0:generate \
-Dopenapi.generator.maven.plugin.inputSpec=openapi.yaml \
-Dopenapi.generator.maven.plugin.generatorName=java
Shows a warning:
[WARNING] allOf with multiple schemas defined. Using only the first one: A
It generates classes A and B. But when calling get()
, the value returned by the call is A
:
DefaultApi api = new DefaultApi();
A a = api.get();
I expected instead a composite object with A
and B
properties (attA
and attB
), like this (result from https://editor.swagger.io/):
Related issues/PRs
Suggest a fix
Issue Analytics
- State:
- Created 2 years ago
- Reactions:30
- Comments:35 (4 by maintainers)
Top Results From Across the Web
openapi-generator-maven-plugin (Java) does not handle allOf ...
With org.openapitools:openapi-generator-maven-plugin , I have noticed that using allOf composed of multiple objects in a response does not ...
Read more >Documentation for the spring Generator
Generates a Java SpringBoot Server application using the SpringDoc integration. #CONFIG OPTIONS. These options may be applied as additional- ...
Read more >Inheritance and Polymorphism - Swagger
OAS 3 This guide is for OpenAPI 3.0. Inheritance and Polymorphism. Model Composition. In your API, you may have model schemas that share...
Read more >Generate Server Code Using OpenAPI Generator
In this blog, you will learn how to generate server code using the OpenAPI Generator based on an OpenAPI specification. The code will...
Read more >An adventure in OpenAPI V3 code generation | Mux blog
It's an easy warning to ignore, especially given that OpenAPI Generator is pretty chatty as it generates code. When you see this warning,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess this is the cause for other issues :
And I have the same issue with html2 generators also…
@paulbors of course editing the spec is possible (and that’s the solution we used now), but this is not very convenient if the openapi evolves : we have to manually change our version to match the new version.
Besides, as you said editing the openapi is just a workaround.
That’s why I opened this issue : the fact that the generator does not generate right classes when providing a valid openapi spec (as in my example) is probably a bug and as so probably needs to be fixed.