fix(python-fastapi): multipart array files and Form/File wire-name aliases - #24381
Merged
wing328 merged 3 commits intoJul 22, 2026
Merged
Conversation
…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.
wing328
reviewed
Jul 22, 2026
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.
Type multipart array-of-binary fields as
List[UploadFile]instead of a singleUploadFileso FastAPI binds multiple parts with the same field name. Emitalias="{{baseName}}"onForm(...)andFile(...)likeQuery(...)(#17111), keeping snake_case Python parameters while matching OpenAPI wire names (e.g.additionalMetadata,statusArray).Problem
multipart/form-datawas typed as a singleUploadFileafter [python-fastapi] type binary multipart fields as UploadFile #23793 (single-file fix only). Clients and specs that send multiple parts with the same name (seeform-multipart-binary-array.yaml) did not match the generated stub.Query(..., alias=...). PetstoreuploadImagemetadata (additionalMetadata) and mixed multipart fields (statusArray) could not be bound from wire names generated by typical clients (e.g.typescript-fetch).Changes
PythonFastAPIServerCodegen.uploadFileFormParamTyping: useList[UploadFile]/Optional[List[UploadFile]]whenisArray && isFile.endpoint_argument_definition.mustache: addalias="{{baseName}}"for form params (covers bothFormandFile).PythonFastAPIServerCodegenTest: regressions onform-multipart-binary-array.yamlandpetstore.yaml.samples/server/petstore/python-fastapiviabin/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.shRelated
UploadFile(does not cover arrays)Queryalias for camelCase (this PR extends the same pattern toForm/File)List[UploadFile]or multipart Form aliasPR checklist
./bin/generate-samples.sh bin/configs/*.yamlnot run; only the affectedpython-fastapisample was regenerated.)Commit all changed files (including sample regen).
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
List[UploadFile](orOptional[List[UploadFile]]) so repeated parts bind correctly.Form(...)andFile(...)now includealias="{{baseName}}"(parity withQuery(...)) to match wire names likeadditionalMetadataandstatusArray.Tests
Written for commit 6635d72. Summary will update on new commits.