Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(java-spring): add operationIdAsConstant option to generate String constant holding operationId#24479

Open
Rokko11 wants to merge 1 commit into
OpenAPITools:masterOpenAPITools/openapi-generator:masterfrom
Rokko11:masterRokko11/openapi-generator:masterCopy head branch name to clipboard
Open

feat(java-spring): add operationIdAsConstant option to generate String constant holding operationId#24479
Rokko11 wants to merge 1 commit into
OpenAPITools:masterOpenAPITools/openapi-generator:masterfrom
Rokko11:masterRokko11/openapi-generator:masterCopy head branch name to clipboard

Conversation

@Rokko11

@Rokko11 Rokko11 commented Jul 26, 2026

Copy link
Copy Markdown
  • When flag operationIdAsConstant is enabled, the operationId is getting extracted as a constant - similar to the PATH constant
  • Update docs and verify samples

PR checklist

  • [x ] Read the contribution guidelines.
  • [ x] Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • [x ] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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 operationIdAsConstant to the Java Spring generator to expose an OPERATION_<OPERATION_ID> String constant per operation and use it in @Operation(operationId=...). This reduces duplication and aligns with existing PATH_* constants.

  • New Features
    • Adds CLI/config option operationIdAsConstant (default false) in Spring; when enabled, API interfaces generate OPERATION_<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.

Review in cubic

…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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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|

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.