[Java] Fix XmlEnumValue generation for URI enums
Description
Fixes #24236.
When the Java generator is used with withXml=true, URI enum values are currently rendered as Java expressions inside @XmlEnumValue:
@XmlEnumValue(URI.create("https://example.com"))
Since @XmlEnumValue expects a string, the generated model does not compile.
This change preserves the original OpenAPI enum value as rawValue in EnumVarMap, alongside the existing language-specific value. Java templates pass rawValue through a reusable javaStringLiteral lambda when generating @XmlEnumValue. This produces:
@XmlEnumValue("https://example.com")
HTTPS_EXAMPLE_COM(URI.create("https://example.com"))
The Java-specific expression remains available for the enum constructor, while the XML annotation receives a properly quoted and escaped string literal.
The same XML annotation handling is applied to Groovy, JAX-RS CXF/CDI/CXF-ext/spec, Helidon, and Micronaut enum templates. Injected unknown-default enum entries also receive rawValue, keeping their metadata consistent with regular enum entries.
Existing PHP and TypeScript Fetch tests were updated to include rawValue in their expected enum metadata. All 34 tests in those two classes pass. The 285 selected JAX-RS, Helidon, Micronaut, and CXF tests also passed.
Tests were added to verify:
- URI enums generate valid XML annotations.
- URI enum constructors continue using URI.create(...).
- Top-level and inner enums are handled.
- Generic, OkHttp/Gson, and native template paths are covered.
- Quotes and backslashes in raw enum values are escaped as valid Java string literals.
- DefaultCodegen preserves the original typed enum value in rawValue.
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*.
IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08) @KannaKim (2026/07)
Summary by cubic
Fixes #24236. With withXml=true, the Java generator rendered URI enum values as Java expressions in @XmlEnumValue (e.g., @XmlEnumValue(URI.create("https://example.com"))), which doesn't compile because the annotation expects a string. Now the raw OpenAPI value is emitted as a quoted, escaped string literal, while the constructor keeps the Java expression.
Bug Fixes
- Preserves the original OpenAPI value as
rawValueinEnumVarMapand emits it via a newjavaStringLiterallambda, escaping quotes and backslashes. - Updates top-level and inner enum templates across Java, JavaJaxRS, Groovy, Helidon, and Micronaut generators, and keeps Avro symbol sanitization aligned with raw values.
- Adds tests for URI enums, inner enums, string escaping, and Avro raw-value preservation.