OpenAPITools / OpenAPITools/openapi-generator
[BUG][Spring] Named schemas referenced only inside allOf compositions are not generated as standalone model classes
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description:
When using the spring generator with OAS 3.1.0, named schemas that are only referenced from within an allOf composition (not directly from an operation response or another top-level schema property) are not generated as standalone Java classes. The generator creates inline classes that attempt to reference these missing classes, causing compilation failures.
openapi-generator version: 7.21.0
Generation target: spring (spring-boot library)
Minimal reproducible spec:
openapi: "3.1.0"
info:
title: Test API
version: 1.0.0
servers:
- url: /api
paths:
/items:
get:
operationId: getItems
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/ItemListResponse'
components:
schemas:
BaseResponse:
type: object
required:
- txnId
- timestamp
properties:
txnId:
type: string
timestamp:
type: string
format: date-time
discriminator:
propertyName: txnId
ItemListResponse:
type: object
allOf:
- $ref: '#/components/schemas/BaseResponse'
- type: object
properties:
items:
type: array
items:
$ref: '#/components/schemas/Item'
Item:
type: object
required:
- details
- subItems
properties:
id:
type: string
details:
type: array
items:
$ref: '#/components/schemas/ItemDetail'
subItems:
type: array
items:
$ref: '#/components/schemas/Item'
ItemDetail:
type: object
properties:
name:
type: string
value:
type: string
Command:
java -jar openapi-generator-cli-7.21.0.jar generate \
-i spec.yaml \
-g spring \
--library spring-boot \
--additional-properties=useJakartaEe=true,useSpringBoot3=true,interfaceOnly=true,delegatePattern=true
Expected behavior:
The generator should produce standalone Java classes for all named schemas: BaseResponse, ItemListResponse, Item, and ItemDetail.
Actual behavior:
Item.java is NOT generated
ItemDetail.java is NOT generated
The generator creates an inline class GetItems200ResponseAllOfItemsInner.java that imports and extends Item, but Item.java doesn't exist
Similarly, GetItems200ResponseAllOfItemsInnerDetailsInner.java references ItemDetail which doesn't exist
Compilation fails with cannot find symbol errors
Key observation:
Item and ItemDetail are only referenced from within the allOf inline composition in ItemListResponse. They are not directly referenced by any operation response or top-level property. If Item is also referenced directly (e.g., as a standalone response schema on another endpoint), the generator produces it correctly.
Workarounds attempted (none resolved):
--inline-schema-name-mappings — mappings not applied
schemaMappings — no effect
openapiNormalizer REF_AS_PARENT_IN_ALLOF=true — no effect
true config option — no effect
Related issues: #1123, #21006, #11323
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 minimal OAS 3.1 spec with the documented Spring generator command, then inspect schema/model discovery and allOf handling in the Spring generator. Add a regression case covering BaseResponse, ItemListResponse, Item, and ItemDetail, and verify that all four standalone classes are generated and compile without missing-symbol errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring, spring-boot
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100