Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Python-fastapi] File input incorrectly generated with FastAPI Form #20115

Open
5 of 6 tasks
reyescabello opened this issue Nov 15, 2024 · 0 comments
Open
5 of 6 tasks

Comments

@reyescabello
Copy link

reyescabello commented Nov 15, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating the specified content in the OpenAPI file, the endpoint that receives a file generates an input of type string in the generated Swagger UI. This happens because the generated FastAPI endpoint uses a Form.

We compared this case with another application using the same file, where the input is correctly generated as a file upload field.

openapi-generator version

v7.9.0

OpenAPI declaration file content or url

https://gist.github.com/reyescabello/6cd965708fd0b03e8eadb9f3c0c0a899#file-query_param_example-yml

Generation Details

Generated with jar:

java -jar openapi-generator-cli.jar generate -i openapi.yml -g python-fastapi -o openapi_server

Steps to reproduce

When generating the specified content in the OpenAPI file, the endpoint that includes the file looks like this:

async def upload_post(
    file: str = Form(None, description=""),
) -> None:
    
    return await BaseExampleApi.subclasses[0]().upload_post(file)

And this is what it looks like in swagger.

image

The expected code is something like this:

async def upload_post(
    file: UploadFile,
) -> None:
    
    return await BaseExampleApi.subclasses[0]().upload_post(file)
Related issues/PRs
Suggest a fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant