fix(python-fastapi): map binary response type file to bytes
Description
Fixes invalid -> file / "model": file for binary (application/octet-stream + format: binary) response bodies in python-fastapi (#20775).
Python 3 has no built-in file type, so generated stubs raised NameError on import and broke IDE typing. This change maps OAS file / binary to built-in bytes in PythonFastAPIServerCodegen only (minimal scope). Multipart upload fields still use FastAPI UploadFile via the existing form-param override (#23793).
What changed
typeMapping.put("file", "bytes")andtypeMapping.put("binary", "bytes")inPythonFastAPIServerCodegen- Regression sample:
modules/openapi-generator/src/test/resources/3_0/issue_20775.yaml(200/206 + optionalRange) - Tests:
PythonFastapiCodegenTest/PythonFastAPIServerCodegenTestassert-> bytes/"model": bytesand absence of barefile
Verification
./mvnw clean package -DskipTests
./bin/generate-samples.sh ./bin/configs/python*.yaml
./bin/utils/export_docs_generators.sh
mvn -pl modules/openapi-generator -am \
-Dtest=PythonFastapiCodegenTest,PythonFastAPIServerCodegenTest \
-Dsurefire.failIfNoSpecifiedTests=false test
No samples/ diff: current python-fastapi petstore has no binary response endpoints (only multipart upload). Coverage is via issue_20775.yaml unit generation.
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/python*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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. - @krjakbrjak (Python FastAPI)
Summary by cubic
Maps binary response bodies to bytes in python-fastapi server generation to replace the invalid Python file type. This prevents import errors and fixes typing for application/octet-stream responses.