OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] openapi-generator-maven-plugin does not handle allOf composed of multiple objects
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 (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
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 by running the Maven plugin command with the supplied openapi.yaml and inspect the generated DefaultApi return type and the A and B classes. Trace the handling of the response schema's multiple allOf references from the Maven generation entry point. Done means the generated result combines attA and attB rather than selecting only A, and the warning is no longer produced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100