fix(python-fastapi): omit security imports for unauthenticated APIs - #24809
Merged
Conversation
KannaKim
marked this pull request as draft
August 30, 2026 03:29
KannaKim
marked this pull request as ready for review
August 30, 2026 04:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #23008.
Summary
The Python FastAPI API template unconditionally imports
TokenModel, even when an API has no authenticated operations.When only APIs and models are generated, supporting files such as
extra_models.pyare skipped. The resulting API therefore imports a module that was not generated:This PR emits the
TokenModelandsecurity_apiimports only when the API has security imports.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.
@cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10)
Summary by cubic
Fixes the Python FastAPI template importing
TokenModelandsecurity_apifor APIs with no authenticated operations, which previously referenced modules that were not generated.extra_models.TokenModeland security API imports only when the API has security imports.Written for commit 5a949f6. Summary will update on new commits.