[BUG][java] Discriminator default for direct property enum $ref generates String.<value>
Author: mrickenCreated Sep 4, 2026Updated Sep 8, 2026
LabelsIssue: Bug
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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)
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: stringReproduction
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:
public StockArchiveCategoryEvent() {
this.category = String.ARCHIVE;
}Compilation fails:
error: cannot find symbol
symbol: variable ARCHIVE
location: class StringThe 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.
Source: OpenAPITools/openapi-generator