feat(core): expose request body named examples to templates - #24707
feat(core): expose request body named examples to templates#24707Mattias-Sehlstedt wants to merge 1 commit into
Conversation
f28673c to
8877de6
Compare
8877de6 to
321ce8d
Compare
|
@Mattias-Sehlstedt thanks for the PR. I've used our code successfully in a custom generator. Could you add the equivalent to CodegenResponse? Currently we have We loose the summary and the description of the swagger For better customization, the 2 Currently I do something like this: |
|
I think they both make sense, and that example generation and management in general could be harmonized and clarified so that it would be easier to handle them. But I am not sure that I would want to introduce those changes in this PR, since this is manly target against the exact issue reported. I could create a new issue based upon your suggestions and look into refactoring examples management in general. When you suggest better extension of the |
|
@Mattias-Sehlstedt a configurable class name of the ExampleGenerator can also be used. Similar to the extensible OpenapiNormalizer |
|
The more I look at the example structures, the less I like it.
How can we make it more consistent? To avoid breaking changes, we could have a new CodeGenSample and deprecate the existing example fields |
Adds so that any
examplesdefined in a request body are properly attached to aCodegenParameter'sexamplesso that they can be accessed within the mustache templates. This logic already exists for when reading a swagger-core OASParameterobject, but have now also been extended to request bodies.Fixes #23607
PR checklist
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.
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.
Written for commit 321ce8d. Summary will update on new commits.