Skip to content

feat(core): expose request body named examples to templates - #24707

Open
Mattias-Sehlstedt wants to merge 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:expose-request-body-examples-in-mustache
Open

feat(core): expose request body named examples to templates#24707
Mattias-Sehlstedt wants to merge 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:expose-request-body-examples-in-mustache

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Adds so that any examples defined in a request body are properly attached to a CodegenParameter's examples so that they can be accessed within the mustache templates. This logic already exists for when reading a swagger-core OAS Parameter object, but have now also been extended to request bodies.

Fixes #23607

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 all named request body examples to mustache via CodegenParameter.examples. Previously only a single example value was available; now the examples map from the request body’s first media type is attached while CodegenParameter.example remains unchanged.

  • fromRequestBody now sets examples from the first content media type when present.
  • Add getFirstContentMediaType and hasMediaType helpers; refactor getContentType, addConsumesInfo, getConsumesInfo, and addProducesInfo to use them (null-safety, no behavior change).
  • Add tests and a spec path (/example6/multiple_examples) verifying multiple request body examples are accessible.
  • No template migrations required; templates can iterate over request body examples.

Written for commit 321ce8d. Summary will update on new commits.

Review in cubic

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the expose-request-body-examples-in-mustache branch from f28673c to 8877de6 Compare August 14, 2026 10:20
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the expose-request-body-examples-in-mustache branch from 8877de6 to 321ce8d Compare August 14, 2026 10:21
@Mattias-Sehlstedt Mattias-Sehlstedt changed the title [Core] Add support for reading all request body examples in mustache feat(core): expose request body named examples to templates Aug 14, 2026
@Mattias-Sehlstedt
Mattias-Sehlstedt marked this pull request as ready for review August 14, 2026 10:50

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

No issues found across 3 files

Re-trigger cubic

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