Skip to content

fix(python-fastapi): omit security imports for unauthenticated APIs - #24809

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
KannaKim:fix-23008
Sep 1, 2026
Merged

fix(python-fastapi): omit security imports for unauthenticated APIs#24809
wing328 merged 1 commit into
OpenAPITools:masterfrom
KannaKim:fix-23008

Conversation

@KannaKim

@KannaKim KannaKim commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

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.py are skipped. The resulting API therefore imports a module that was not generated:

from issue_23008_api.models.extra_models import TokenModel

This PR emits the TokenModel and security_api imports only when the API has security imports.

PR checklist

  • Read the contribution guidelines.
  • 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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@cbornet (2017/09) @tomplus (2018/10) @krjakbrjak (2023/02) @fa0311 (2023/10)


Summary by cubic

Fixes the Python FastAPI template importing TokenModel and security_api for APIs with no authenticated operations, which previously referenced modules that were not generated.

  • Emits extra_models.TokenModel and security API imports only when the API has security imports.
  • Adds a regression test and a minimal OpenAPI spec that reproduces the unauthenticated case.

Written for commit 5a949f6. Summary will update on new commits.

Review in cubic

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

Re-trigger cubic

@KannaKim KannaKim closed this Aug 30, 2026
@KannaKim KannaKim reopened this Aug 30, 2026
@KannaKim
KannaKim marked this pull request as draft August 30, 2026 03:29
@KannaKim
KannaKim marked this pull request as ready for review August 30, 2026 04:07

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

Re-trigger cubic

@wing328
wing328 merged commit c826d49 into OpenAPITools:master Sep 1, 2026
16 checks passed
@wing328 wing328 added this to the 7.26.0 milestone Sep 1, 2026
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] [FAST API] Given supportingFiles-false, APIs still use a not-generated extra_modules.py

2 participants