Repository navigation
[BUG][Java] useOneOfInterfaces generates incompatible discriminator return types for inline enums #24959
Description
Description
With useOneOfInterfaces=true, the Java client generator can produce code that does not compile when the members of a discriminated oneOf define the discriminator as inline enums.
The generated one-of interface declares:
public interface SchemaProperty {
String getType();
}But its generated implementations declare their own enum return types:
public TypeEnum getType() {
return type;
}This fails compilation because TypeEnum is not covariant with String.
OpenAPI Generator version
7.25.0
Generator configuration
- Generator:
java - Library:
restclient useOneOfInterfaces=true
Minimal OpenAPI schema
openapi: 3.0.3
info:
title: OneOf discriminator reproduction
version: 1.0.0
paths: {}
components:
schemas:
SchemaProperty:
discriminator:
propertyName: type
mapping:
array: '#/components/schemas/ArrayProperty'
string: '#/components/schemas/BasicProperty'
number: '#/components/schemas/BasicProperty'
oneOf:
- $ref: '#/components/schemas/ArrayProperty'
- $ref: '#/components/schemas/BasicProperty'
ArrayProperty:
type: object
required:
- type
- items
properties:
type:
type: string
enum:
- array
items:
$ref: '#/components/schemas/SchemaProperty'
BasicProperty:
type: object
required:
- type
properties:
type:
type: string
enum:
- string
- numberGenerated result
The generated interface has:
public interface SchemaProperty {
String getType();
}The generated implementations have methods such as:
public ArrayProperty.TypeEnum getType()and:
public BasicProperty.TypeEnum getType()Compilation consequently fails with errors such as:
ArrayProperty is not abstract and does not override abstract method getType() in SchemaProperty
getType() in ArrayProperty cannot implement getType() in SchemaProperty
return type ArrayProperty.TypeEnum is not compatible with java.lang.String
Expected behavior
The generated models should compile when useOneOfInterfaces=true.
The interface discriminator getter must use a return type compatible with all generated implementations. For example, generating Object getType() avoids the incompatible return types, although there may be a more strongly typed solution.
Related issues
- [REQ][JAVA] oneOf discriminator type string with enum defined #12412 fixed enum discriminator discovery for one schema arrangement, but comments after its closure report that other arrangements still generate the incompatible
Stringreturn type. - [BUG] Java generator: discriminator enum type not compatible with Spring Boot 3.5.5 / oneOf interfaces #22541 / [core] Add introspection support for discovering the discriminator type in a oneOf allOf polymorphic structure #24158 fixed discriminator discovery through
oneOf→allOfinheritance.
The schema above does not use allOf, and the problem remains reproducible with 7.25.0.
Activity
jpfinne commentedon Sep 17, 2026
@Pattrigue can you try with the latest snapshot?
It compiles correctly on my machine:
It should be fixed by #24812
Pattrigue commentedon Sep 18, 2026
@jpfinne latest snapshot fixes it, would be nice to get this out as soon as possible, we're currently using an awkward workaround.
Pattrigue commentedon Sep 30, 2026
@jpfinne Any updates?
jpfinne commentedon Sep 30, 2026
@Pattrigue, it will be in the next release. It was planned for 26/09, so it will come hopefully soon.
I don't have the privilege to release...
Pattrigue commentedon Oct 6, 2026
@jpfinne just saw it was released, but the latest release introduced another problem:
#25160