diff --git a/docs/generators/jaxrs-cxf-cdi.md b/docs/generators/jaxrs-cxf-cdi.md index 54e88fd00a53..55963cc41b83 100644 --- a/docs/generators/jaxrs-cxf-cdi.md +++ b/docs/generators/jaxrs-cxf-cdi.md @@ -81,6 +81,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi| |title|a title describing the application| |OpenAPI Server| |useBeanValidation|Use BeanValidation API annotations| |true| +|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useJakartaSecurityAnnotations|Whether to generate Jakarta security annotations (@RolesAllowed, @PermitAll). Requires useJakartaEe=true. Currently only supported when library is set to quarkus.| |false| |useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false| diff --git a/docs/generators/jaxrs-spec.md b/docs/generators/jaxrs-spec.md index b5225bffd43e..f3684ae282b3 100644 --- a/docs/generators/jaxrs-spec.md +++ b/docs/generators/jaxrs-spec.md @@ -82,6 +82,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi| |title|a title describing the application| |OpenAPI Server| |useBeanValidation|Use BeanValidation API annotations| |true| +|useEnumCaseInsensitive|Use `equalsIgnoreCase` when String for enum comparison| |false| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| |useJakartaSecurityAnnotations|Whether to generate Jakarta security annotations (@RolesAllowed, @PermitAll). Requires useJakartaEe=true. Currently only supported when library is set to quarkus.| |false| |useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java index c48002c8ba3c..65f72b41faf6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java @@ -56,6 +56,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen { public static final String OPEN_API_SPEC_FILE_LOCATION = "openApiSpecFileLocation"; public static final String GENERATE_JSON_CREATOR = "generateJsonCreator"; public static final String USE_JAKARTA_SECURITY_ANNOTATIONS = "useJakartaSecurityAnnotations"; + public static final String USE_ENUM_CASE_INSENSITIVE = "useEnumCaseInsensitive"; public static final String QUARKUS_LIBRARY = "quarkus"; public static final String THORNTAIL_LIBRARY = "thorntail"; @@ -73,6 +74,9 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen { private boolean useMutiny = false; private boolean useJakartaSecurityAnnotations = false; + @Setter + private boolean useEnumCaseInsensitive = false; + private final JakartaSecurityAnnotationProcessor jakartaSecurityAnnotationProcessor = new JakartaSecurityAnnotationProcessor(); @Getter @Setter @@ -155,6 +159,7 @@ public JavaJAXRSSpecServerCodegen() { cliOptions.add(CliOption.newBoolean(USE_MUTINY, "Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.", useMutiny)); cliOptions.add(CliOption.newBoolean(USE_JAKARTA_SECURITY_ANNOTATIONS, "Whether to generate Jakarta security annotations (@RolesAllowed, @PermitAll). Requires useJakartaEe=true. Currently only supported when library is set to quarkus.", useJakartaSecurityAnnotations)); cliOptions.add(CliOption.newBoolean(GENERATE_JSON_CREATOR, "Whether to generate @JsonCreator constructor for required properties.", generateJsonCreator)); + cliOptions.add(CliOption.newBoolean(USE_ENUM_CASE_INSENSITIVE, "Use `equalsIgnoreCase` when String for enum comparison", useEnumCaseInsensitive)); } @Override @@ -197,6 +202,7 @@ public void processOpts() { } convertPropertyToBooleanAndWriteBack(GENERATE_JSON_CREATOR, this::setGenerateJsonCreator); + convertPropertyToBooleanAndWriteBack(USE_ENUM_CASE_INSENSITIVE, this::setUseEnumCaseInsensitive); if (additionalProperties.containsKey(OPEN_API_SPEC_FILE_LOCATION)) { openApiSpecFileLocation = additionalProperties.get(OPEN_API_SPEC_FILE_LOCATION).toString(); diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts index d23b075ea7d2..4ea9062e1ed8 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/enum-test.ts @@ -142,7 +142,7 @@ export type EnumTestEnumNumberEnum = typeof EnumTestEnumNumberEnum[keyof typeof * Check if a given object implements the EnumTest interface. */ export function instanceOfEnumTest(value: object): value is EnumTest { - if ((!('enumStringRequired' in value) && !('enum_string_required' in value)) || (value['enumStringRequired'] === undefined && value['enum_string_required'] === undefined)) return false; + if ((!('enumStringRequired' in (value as Record)) && !('enum_string_required' in (value as Record))) || ((value as Record)['enumStringRequired'] === undefined && (value as Record)['enum_string_required'] === undefined)) return false; return true; } diff --git a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/format-test.ts b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/format-test.ts index 822bb60636fb..c80896e71861 100644 --- a/samples/client/petstore/typescript-fetch/builds/kebab-case/models/format-test.ts +++ b/samples/client/petstore/typescript-fetch/builds/kebab-case/models/format-test.ts @@ -122,7 +122,7 @@ export interface FormatTest { */ export function instanceOfFormatTest(value: object): value is FormatTest { if (!('number' in value) || value['number'] === undefined) return false; - if ((!('_byte' in value) && !('byte' in value)) || (value['_byte'] === undefined && value['byte'] === undefined)) return false; + if ((!('_byte' in (value as Record)) && !('byte' in (value as Record))) || ((value as Record)['_byte'] === undefined && (value as Record)['byte'] === undefined)) return false; if (!('date' in value) || value['date'] === undefined) return false; if (!('password' in value) || value['password'] === undefined) return false; return true;