Skip to content

[python-fastapi] Use ... as default value rather than None (#22494)#23398

Open
zhornback wants to merge 2 commits intoOpenAPITools:masterfrom
zhornback:fix_issue22494
Open

[python-fastapi] Use ... as default value rather than None (#22494)#23398
zhornback wants to merge 2 commits intoOpenAPITools:masterfrom
zhornback:fix_issue22494

Conversation

@zhornback
Copy link
Copy Markdown
Contributor

@zhornback zhornback commented Mar 30, 2026

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:
    ./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.
  • [ X ] File the PR against the correct branch: master (upcoming 7.x.0 minor 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 ... as the default for required params instead of None, so FastAPI correctly treats them as required. Fixes #22494 and aligns generated endpoints with OpenAPI “required” semantics across all param types.

  • Bug Fixes
    • Update endpoint_argument_definition.mustache to use ... when required, otherwise None, for Query, Path, Header, Cookie, Body, Form, and File.
    • Regenerate samples to reflect required params using ... (e.g., pet/order/user bodies, status/tags/username/password queries).

Written for commit 63a2d8a. Summary will update on new commits.

…ols#22494)

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

Issue: OpenAPITools#22494
@zhornback zhornback changed the title [python-fastapi] Use ... as default value rather than of None (#22494) [python-fastapi] Use ... as default value rather than None (#22494) Mar 30, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

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][PYTHON-FASTAPI] Required query parameters generated with Query(None, ...) instead of Query(..., ...)

1 participant