Skip to content

fix(python-fastapi): multipart array files and Form/File wire-name aliases - #24381

Merged
wing328 merged 3 commits into
OpenAPITools:masterfrom
JerrySLau:fix_fastapi_multipart_array
Jul 22, 2026
Merged

wing328 merged 3 commits into
OpenAPITools:masterfrom
JerrySLau:fix_fastapi_multipart_array

Conversation

@JerrySLau

@JerrySLau JerrySLau commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Type multipart array-of-binary fields as List[UploadFile] instead of a single UploadFile so FastAPI binds multiple parts with the same field name. Emit alias="{{baseName}}" on Form(...) and File(...) like Query(...) (#17111), keeping snake_case Python parameters while matching OpenAPI wire names (e.g. additionalMetadata, statusArray).

Problem

  1. Array of binary in multipart/form-data was typed as a single UploadFile after [python-fastapi] type binary multipart fields as UploadFile #23793 (single-file fix only). Clients and specs that send multiple parts with the same name (see form-multipart-binary-array.yaml) did not match the generated stub.
  2. camelCase form/file fields were renamed to snake_case in Python without a FastAPI alias, while query parameters already used Query(..., alias=...). Petstore uploadImage metadata (additionalMetadata) and mixed multipart fields (statusArray) could not be bound from wire names generated by typical clients (e.g. typescript-fetch).

Changes

  • PythonFastAPIServerCodegen.uploadFileFormParamTyping: use List[UploadFile] / Optional[List[UploadFile]] when isArray && isFile.
  • endpoint_argument_definition.mustache: add alias="{{baseName}}" for form params (covers both Form and File).
  • PythonFastAPIServerCodegenTest: regressions on form-multipart-binary-array.yaml and petstore.yaml.
  • Regenerated samples/server/petstore/python-fastapi via bin/configs/python-fastapi.yaml.

Tests

./mvnw clean package -DskipTests -Dmaven.javadoc.skip=true -Djacoco.skip=true
./mvnw -pl modules/openapi-generator-core,modules/openapi-generator -am \
  -Dtest=PythonFastAPIServerCodegenTest -Dsurefire.failIfNoSpecifiedTests=false test
./bin/generate-samples.sh bin/configs/python-fastapi.yaml
./bin/utils/export_docs_generators.sh

Related

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package -DskipTests -Dmaven.javadoc.skip=true -Djacoco.skip=true
    ./bin/generate-samples.sh bin/configs/python-fastapi.yaml
    ./bin/utils/export_docs_generators.sh
    
    (Full ./bin/generate-samples.sh bin/configs/*.yaml not run; only the affected python-fastapi sample was regenerated.)
    Commit all changed files (including sample regen).
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

FYI @cbornet @tomplus @krjakbrjak @fa0311 @multani


Summary by cubic

Fixes FastAPI multipart handling by generating List[UploadFile] for array file fields and adding aliases to form/file params to match OpenAPI wire names. FastAPI now binds multiple files correctly and accepts camelCase inputs while keeping snake_case parameters.

  • Bug Fixes

    • Multipart array-of-binary form fields now use List[UploadFile] (or Optional[List[UploadFile]]) so repeated parts bind correctly.
    • Form(...) and File(...) now include alias="{{baseName}}" (parity with Query(...)) to match wire names like additionalMetadata and statusArray.
  • Tests

    • Added regression tests for multipart array files and form/file aliasing; updated the FastAPI sample.

Written for commit 6635d72. Summary will update on new commits.

Review in cubic

…iases

Type multipart array-of-binary fields as List[UploadFile] instead of a
single UploadFile so FastAPI binds multiple parts with the same field name.
Emit alias="{{baseName}}" on Form(...) and File(...) like Query(...),
keeping snake_case Python parameters while matching OpenAPI wire names
(e.g. additionalMetadata, statusArray).

Add regression tests in PythonFastAPIServerCodegenTest using
form-multipart-binary-array.yaml and petstore.yaml.

@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

Re-trigger cubic

@wing328
wing328 merged commit 8f36063 into OpenAPITools:master Jul 22, 2026
17 checks passed
@wing328 wing328 added this to the 7.25.0 milestone Jul 22, 2026
@JerrySLau
JerrySLau deleted the fix_fastapi_multipart_array branch July 22, 2026 23:46
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.

2 participants