Skip to content

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

Open
zhornback wants to merge 5 commits into
OpenAPITools:masterfrom
zhornback:fix_issue22494
Open

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

Conversation

@zhornback

@zhornback zhornback commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

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 ... 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.mustache to use ... when required, else None, across Query, Path, Header, Cookie, Body, Form, and File.
    • Update tests to expect Body(...) and required Form(...); regenerate petstore samples accordingly.
  • Dependencies

    • In kotlin-spring-cloud-4 sample: bump Jackson 3 from 3.1.0 to 3.1.5 for tools.jackson.* artifacts, and update Gradle wrapper to 8.14.5.

Written for commit 4fe0d0d. Summary will update on new commits.

Review in cubic

@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

@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 4 files

@darkobardic

darkobardic commented May 6, 2026

Copy link
Copy Markdown

@zhornback, thanks for this — filed the original issue #22494 and your fix works correctly against our python-fastapi server (Query(...) for required, 422 on missing params).

Any chance you could rebase? The conflict looks like just regenerated samples, and the circleci: node2 failure looks flaky (sharded runner, all ~15 other checks green).

@zhornback

Copy link
Copy Markdown
Contributor Author

Looks like some bitrot set in. Looking into it.

@darkobardic

Copy link
Copy Markdown

Thanks @zhornback!

@wing328, would you mind taking a look when you have a moment? Small python-fastapi fix for #22494. Thanks!

@wing328

wing328 commented Jul 30, 2026

Copy link
Copy Markdown
Member

please resolve the merge conflicts and i'll try to get it merged into upcoming release (v7.25.0) 🙏

…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
Since the initial PR, a new test was added expecting None rather than
'...'.  Changing test and samples as needed.
A new test needed to be adjusted, the Form was required so ... is more
appropriate than None.
@zhornback

Copy link
Copy Markdown
Contributor Author

@wing328 I have resolved the merge conflicts and adjusted new tests. Tests are passing.

Tag you're it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

3 participants