From ab0309ecdcc8ec8f8d53dc109585f7348f512de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Fri, 23 Feb 2024 09:02:22 +0100 Subject: [PATCH] Prevent enum item names being reserved keywords (#17804) --- .../java/org/openapitools/codegen/DefaultCodegen.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index bf597f4d2c6c..875ddfc85be5 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -928,10 +928,14 @@ public String toEnumVarName(String value, String datatype) { String var = value.replaceAll("\\W+", "_").toUpperCase(Locale.ROOT); if (var.matches("\\d.*")) { - return "_" + var; - } else { - return var; + var = "_" + var; + } + + if (reservedWords.contains(var)) { + return escapeReservedWord(var); } + + return var; } public boolean specVersionGreaterThanOrEqualTo310(OpenAPI openAPI) {