Skip to content

Escape parameter defaults in Java API Javadocs - #24972

Closed
Felix-ming wants to merge 21 commits into
OpenAPITools:masterfrom
Felix-ming:fix/java-default-value-javadoc
Closed

Felix-ming wants to merge 21 commits into
OpenAPITools:masterfrom
Felix-ming:fix/java-default-value-javadoc

Conversation

@Felix-ming

@Felix-ming Felix-ming commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #24852.

Problem

The Java okhttp-gson generator renders parameter default values directly in @param Javadocs. Values containing Java block-comment delimiters can terminate or start a comment in the generated source and make the client fail to compile. This is observable downstream in apache/airflow#72466.

Solution

  • Preserve the runtime default value unchanged.
  • Add a Java-specific vendor extension containing a comment-safe value for Javadocs.
  • Use the escaped value for defaults rendered by the Java API Javadoc templates across the supported client libraries.
  • Add a regression fixture and test that validates the generated Java source.

Tests

  • ./mvnw -pl modules/openapi-generator -am --batch-mode --no-transfer-progress -Dtest=JavaClientCodegenTest#shouldEscapeParameterDefaultsInOkHttpGsonApiJavadocs -Dsurefire.failIfNoSpecifiedTests=false test
  • ./mvnw -pl modules/openapi-generator -am --batch-mode --no-transfer-progress -Dtest=JavaClientCodegenTest -Dsurefire.failIfNoSpecifiedTests=false test

Both commands pass; the full JavaClientCodegenTest class passes 290 tests.

@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.

1 issue 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="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java:1151">
P2: The shared `JavaClientCodegen.postProcessParameter` now attaches the escaped `x-java-default-value-for-javadoc` extension to every parameter of every Java generator, but only the okhttp-gson api.mustache consumes it. The same compile-breaking Javadoc bug this PR fixes still exists in the other Java library templates that render `{{#defaultValue}}` raw inside `@param` comments (apache-httpclient line 49, feign lines 33/63/100, jersey2 lines 63/100, native lines 325/355/400/423, and equivalents in resttemplate/webclient, etc.). Since the extension is already available to all of them, swapping the one section token in each is a mechanical follow-up; otherwise a user on any other Java library hits the identical failure from apache/airflow#72466.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@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.

All reported issues were addressed across 16 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor

Looks to be a semi-duplicate of #24890?

@Felix-ming

Copy link
Copy Markdown
Contributor Author

You're right — this PR substantially overlaps with #24890 and both address #24852 across the Java API Javadoc templates.

The main implementation difference is that this PR prepares a Java-specific, comment-safe vendor extension in the generator and leaves defaultValue unchanged for generated runtime code. Templates consume that derived value only at Javadoc sinks. It is intentionally narrower than #24890: no Mustache lambda and no unrelated string-example/sample changes.

This seems closer to the generator-side direction discussed on #24890, but I am happy to close this PR in favor of #24890 if that is preferred. Please let me know which direction you would like to keep.

@Felix-ming

Felix-ming commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

This PR is superseded by #24890, which was merged on September 23 and addresses the same JavaDoc default-value escaping across the Java library templates. I’m closing this PR to avoid duplicate maintenance. Thanks for the review and feedback.

@Felix-ming Felix-ming closed this Oct 6, 2026
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.

Java generator: parameter defaultValue not escaped in @param Javadoc, breaks compilation for values containing "*/"

2 participants