feat(java-spring): add operationIdAsConstant option to generate String constant holding operationId#24479
feat(java-spring): add operationIdAsConstant option to generate String constant holding operationId#24479Rokko11 wants to merge 1 commit into
Conversation
…olding the operationId value. - When flag operationIdAsConstant is enabled, the operationId is getting extracted as a constant - similar to the PATH constant - Update docs and verify samples
There was a problem hiding this comment.
2 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="docs/generators/java-camel.md">
<violation number="1" location="docs/generators/java-camel.md:85">
P2: The `java-camel` generator now documents `operationIdAsConstant`, but its `java-camel-server` template does not consume this option, so enabling it silently produces the same output without an operation-ID constant. The option should either be implemented in that generator's template (if intended for Camel) or omitted from the Camel generator's advertised options.</violation>
</file>
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java:352">
P3: The new option description has a user-facing grammar error: `an String` should be `a String`. Updating the CLI description also keeps the generated Spring and Camel documentation wording correct.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| |licenseUrl|The URL of the license| |http://unlicense.org| | ||
| |modelPackage|package for generated models| |org.openapitools.model| | ||
| |openApiNullable|Enable OpenAPI Jackson Nullable library. Not supported by `microprofile` library.| |true| | ||
| |operationIdAsConstant|Generate an String constant in the API interface holding the operationId value.| |false| |
There was a problem hiding this comment.
P2: The java-camel generator now documents operationIdAsConstant, but its java-camel-server template does not consume this option, so enabling it silently produces the same output without an operation-ID constant. The option should either be implemented in that generator's template (if intended for Camel) or omitted from the Camel generator's advertised options.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/generators/java-camel.md, line 85:
<comment>The `java-camel` generator now documents `operationIdAsConstant`, but its `java-camel-server` template does not consume this option, so enabling it silently produces the same output without an operation-ID constant. The option should either be implemented in that generator's template (if intended for Camel) or omitted from the Camel generator's advertised options.</comment>
<file context>
@@ -82,6 +82,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|licenseUrl|The URL of the license| |http://unlicense.org|
|modelPackage|package for generated models| |org.openapitools.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library. Not supported by `microprofile` library.| |true|
+|operationIdAsConstant|Generate an String constant in the API interface holding the operationId value.| |false|
|optionalAcceptNullable|Use `ofNullable` instead of just `of` to accept null values when using Optional.| |true|
|parentArtifactId|parent artifactId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
</file context>
| ); | ||
| cliOptions.add(CliOption.newBoolean(USE_JSPECIFY, "Use Jspecify for null checks", useJspecify)); | ||
| cliOptions.add(CliOption.newString(CLIENT_REGISTRATION_ID, "Client registration ID for OAuth2 in Spring HTTP Interface (@ClientRegistrationId annotation). Requires library=spring-http-interface and useSpringBoot4=true (Spring Security 7).")); | ||
| cliOptions.add(CliOption.newBoolean(OPERATION_ID_AS_CONSTANT, "Generate an String constant in the API interface holding the operationId value.", operationIdAsConstant)); |
There was a problem hiding this comment.
P3: The new option description has a user-facing grammar error: an String should be a String. Updating the CLI description also keeps the generated Spring and Camel documentation wording correct.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java, line 352:
<comment>The new option description has a user-facing grammar error: `an String` should be `a String`. Updating the CLI description also keeps the generated Spring and Camel documentation wording correct.</comment>
<file context>
@@ -347,6 +349,7 @@ public SpringCodegen() {
);
cliOptions.add(CliOption.newBoolean(USE_JSPECIFY, "Use Jspecify for null checks", useJspecify));
cliOptions.add(CliOption.newString(CLIENT_REGISTRATION_ID, "Client registration ID for OAuth2 in Spring HTTP Interface (@ClientRegistrationId annotation). Requires library=spring-http-interface and useSpringBoot4=true (Spring Security 7)."));
+ cliOptions.add(CliOption.newBoolean(OPERATION_ID_AS_CONSTANT, "Generate an String constant in the API interface holding the operationId value.", operationIdAsConstant));
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
supportedLibraries.put(SPRING_CLOUD_LIBRARY,
</file context>
| cliOptions.add(CliOption.newBoolean(OPERATION_ID_AS_CONSTANT, "Generate an String constant in the API interface holding the operationId value.", operationIdAsConstant)); | |
| cliOptions.add(CliOption.newBoolean(OPERATION_ID_AS_CONSTANT, "Generate a String constant in the API interface holding the operationId value.", operationIdAsConstant)); |
PR checklist
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.
cc @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08)
Summary by cubic
Adds an opt‑in
operationIdAsConstantto the Java Spring generator to expose anOPERATION_<OPERATION_ID>String constant per operation and use it in@Operation(operationId=...). This reduces duplication and aligns with existingPATH_*constants.operationIdAsConstant(default false) in Spring; when enabled, API interfaces generateOPERATION_<OPERATION_ID>constants and reference them in the annotation. Docs updated in Spring and Java Camel generator pages.Written for commit 52cc42b. Summary will update on new commits.