[python-fastapi] Use ... as default value rather than None (#22494)
Merged
ZH
4mo ago+60+60+01234567890123456789-33-33-01234567890123456789
With various FastAPI parameters (Query, Path, Header, Cookie, Body, Form, and File) the default value of None is a valid value, but signifies that the parameter is optional. To allow for required parameters, default should either not be set at all or be set to '...' (ellipsis).
Reproduction details can be found in #22494.
fixes #22494
PR checklist
- [ X ] Read the contribution guidelines.
- [ X ] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
- [ X ] Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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. - [ X ] File the PR against the correct branch:
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks) - [ X ] If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having
"fixes #123"present in the PR description) - [ X ] 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
Switch the python-fastapi generator to emit ... for required params and None for optional ones so FastAPI enforces OpenAPI required semantics. Updates tests and regenerated samples; fixes #22494.
-
Bug Fixes
- Simplify
endpoint_argument_definition.mustacheto use...whenrequired, elseNone, acrossQuery,Path,Header,Cookie,Body,Form, andFile. - Update tests to expect
Body(...)and requiredForm(...); regenerate petstore samples accordingly.
- Simplify
-
Dependencies
- In
kotlin-spring-cloud-4sample: bump Jackson 3 from 3.1.0 to 3.1.5 fortools.jackson.*artifacts, and update Gradle wrapper to 8.14.5.
- In