Bug Report Checklist
Describe the bug
The Java client generator produces Java that does not compile when a discriminator property is a direct $ref to an inline enum property. The generated child constructor assigns the discriminator mapping value as though the property were String:
this.category = String.ARCHIVE;
String.ARCHIVE does not exist.
Minimal OpenAPI 3.1 input
openapi: 3.1.0
info:
title: Shared category discriminator
version: 1.0.0
paths: {}
components:
schemas:
CategorySource:
type: object
required:
- category
properties:
category:
type: string
enum:
- ARCHIVE
CategoryEvent:
type: object
required:
- category
properties:
category:
description: Event category
$ref: "#/components/schemas/CategorySource/properties/category"
discriminator:
propertyName: category
mapping:
ARCHIVE: "#/components/schemas/ArchiveCategoryEvent"
ArchiveCategoryEvent:
allOf:
- $ref: "#/components/schemas/CategoryEvent"
- type: object
properties:
value:
type: string
Reproduction
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar \
generate \
-g java \
-i enum-discriminator.yaml \
-o generated \
--skip-validate-spec \
--additional-properties modelNamePrefix=Stock,hideGenerationTimestamp=true
cd generated
mvn -q -DskipTests compile
Actual result
Latest master (b391b2b98c5926ee9842ef3bc863b57c4d824bbe, 7.26.0-SNAPSHOT) generates:
public StockArchiveCategoryEvent() {
this.category = String.ARCHIVE;
}
Compilation fails:
error: cannot find symbol
symbol: variable ARCHIVE
location: class String
The same failure occurs with OpenAPI Generator 7.24.0.
Expected result
The direct property reference should retain the enum type at the discriminator use site. The generated constructor should assign the enum member, rather than String.ARCHIVE, and the generated client should compile.
Bug Report Checklist
Describe the bug
The Java client generator produces Java that does not compile when a discriminator property is a direct
$refto an inline enum property. The generated child constructor assigns the discriminator mapping value as though the property wereString:String.ARCHIVEdoes not exist.Minimal OpenAPI 3.1 input
Reproduction
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar \ generate \ -g java \ -i enum-discriminator.yaml \ -o generated \ --skip-validate-spec \ --additional-properties modelNamePrefix=Stock,hideGenerationTimestamp=true cd generated mvn -q -DskipTests compileActual result
Latest master (
b391b2b98c5926ee9842ef3bc863b57c4d824bbe,7.26.0-SNAPSHOT) generates:Compilation fails:
The same failure occurs with OpenAPI Generator 7.24.0.
Expected result
The direct property reference should retain the enum type at the discriminator use site. The generated constructor should assign the enum member, rather than
String.ARCHIVE, and the generated client should compile.