Skip to content

fix(java-spring): expose requestBody named examples to Mustache template context (#23607) - #24651

Open
anupamchaubey wants to merge 1 commit into
OpenAPITools:masterfrom
anupamchaubey:fix/requestbody-examples-23607
Open

fix(java-spring): expose requestBody named examples to Mustache template context (#23607)#24651
anupamchaubey wants to merge 1 commit into
OpenAPITools:masterfrom
anupamchaubey:fix/requestbody-examples-23607

Conversation

@anupamchaubey

@anupamchaubey anupamchaubey commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #23607.

Description of Changes
Updated AbstractJavaCodegen to correctly populate named requestBody examples from mediaType.getExamples() into codegenParameter.examples, ensuring they are properly exposed to Mustache templates.

Added a unit test in SpringCodegenTest along with a test OpenAPI specification YAML (requestbody_named_examples.yaml) to verify that named request body examples are correctly mapped and available for template rendering.

PR checklist

  • Read the contribution guidelines.
  • 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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Expose named requestBody examples to Mustache templates in the Java Spring generator by propagating MediaType.examples into codegenParameter.examples. This makes all named examples available for template rendering.

  • Bug Fixes
    • Updated AbstractJavaCodegen#setParameterExampleValue to assign mediaType.getExamples() to codegenParameter.examples for requestBody params.
    • Added a unit test in SpringCodegenTest using requestbody_named_examples.yaml; verifies codegenOperation.bodyParam.examples includes named examples ("Jessica", "Ron").

Written for commit c4a41aa. Summary will update on new commits.

Review in 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.

1 issue found across 3 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/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java:8720">
P3: The test starts a full generator run into a temp directory and computes an `outputPath` variable, but the actual assertions never read the generated files — they call `codegen.fromOperation(...)` directly and check the returned `bodyParam.examples` map. As written, the `DefaultGenerator` + `generate()` block and the `outputPath` variable are dead scaffolding that adds runtime cost and noise without verifying anything. I'd suggest dropping the unused `outputPath` and either removing the redundant generator execution, or better, asserting on the rendered template output if the goal is to prove Mustache exposure.</violation>
</file>

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

Re-trigger cubic

generator.setGenerateMetadata(false);

// Run generator
generator.opts(input).generate();

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 test starts a full generator run into a temp directory and computes an outputPath variable, but the actual assertions never read the generated files — they call codegen.fromOperation(...) directly and check the returned bodyParam.examples map. As written, the DefaultGenerator + generate() block and the outputPath variable are dead scaffolding that adds runtime cost and noise without verifying anything. I'd suggest dropping the unused outputPath and either removing the redundant generator execution, or better, asserting on the rendered template output if the goal is to prove Mustache exposure.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java, line 8720:

<comment>The test starts a full generator run into a temp directory and computes an `outputPath` variable, but the actual assertions never read the generated files — they call `codegen.fromOperation(...)` directly and check the returned `bodyParam.examples` map. As written, the `DefaultGenerator` + `generate()` block and the `outputPath` variable are dead scaffolding that adds runtime cost and noise without verifying anything. I'd suggest dropping the unused `outputPath` and either removing the redundant generator execution, or better, asserting on the rendered template output if the goal is to prove Mustache exposure.</comment>

<file context>
@@ -8690,4 +8690,43 @@ public void testReactiveSpringHttpInterfaceSupportListOfStringReturnTypeNoRespon
+        generator.setGenerateMetadata(false);
+
+        // Run generator
+        generator.opts(input).generate();
+
+        // Verify or test directly via CodegenOperation model inspection
</file context>

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.

[BUG][JavaSpring] requestBody named examples (OAS3) not exposed to Mustache template variables

1 participant