Skip to content

refactor: unify handling of content examples parsing - #24653

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:harmonize-content-example-parsing
Aug 10, 2026
Merged

refactor: unify handling of content examples parsing#24653
wing328 merged 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:harmonize-content-example-parsing

Conversation

@Mattias-Sehlstedt

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

Copy link
Copy Markdown
Contributor

I saw #24651 that changes what request body example structure that is propagated to the mustache template. It only changed AbstractJavaCodegen rather than DefaultCodegen, so I got curious regarding why this was the case. I would expect this change to be of interest to all generators. The reason seemed to be that Java overrode the default to some extent.

I have analyzed the structure and found that the generators still have almost everything in common, and that one is basically just the extension of the other. I have thus centralized the logic in the existing ExamplesUtils, and then used that in the different implementers. The reason for this is to ensure that all generators will benefit from improvements when they are introduced (e.g., all only read the first media type, but if someone introduces so that all are read, then that is also something all generators will want to be able to utilize).

This PR also centralized the definition of the reoccurring x-example vendor extension.

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

Unifies request body example parsing by centralizing logic in ExamplesUtils.getContentExample. Standardizes the x-example vendor extension with CodegenConstants.X_EXAMPLE for consistent behavior and logging.

  • Refactors
    • Centralizes content example extraction in ExamplesUtils.getContentExample and uses it in DefaultCodegen and TypeScriptClientCodegen; AbstractJavaCodegen keeps model behavior (warn and ignore complex examples) and delegates to shared logic for primitives.
    • Replaces literal "x-example" with CodegenConstants.X_EXAMPLE in DefaultCodegen, AbstractJavaCodegen, AbstractFSharpCodegen, TypeScriptClientCodegen, RustServerCodegen, and RustServerCodegenDeprecated.
    • Considers only the first media type when resolving examples; the single debug log now lives in ExamplesUtils.

Written for commit ba4d18e. 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.

All reported issues were addressed across 8 files

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

Re-trigger cubic

@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the harmonize-content-example-parsing branch 2 times, most recently from 8f70e09 to d0bdd79 Compare August 9, 2026 22:27
@Mattias-Sehlstedt
Mattias-Sehlstedt force-pushed the harmonize-content-example-parsing branch from d0bdd79 to ba4d18e Compare August 9, 2026 22:36
@wing328
wing328 merged commit 5065aa7 into OpenAPITools:master Aug 10, 2026
15 checks passed
@wing328 wing328 added the Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc. label Aug 10, 2026
@wing328 wing328 added this to the 7.25.0 milestone Aug 10, 2026
@Mattias-Sehlstedt
Mattias-Sehlstedt deleted the harmonize-content-example-parsing branch August 10, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement: Code Cleanup General refactoring, removal of deprecated things, commenting, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants