Skip to content

Can the OpenAPI Schema autogenerated from an UploadFile be customised? #1442

@chan-vince

Description

@chan-vince

First check

  • [✔️] I used the GitHub search to find a similar issue and didn't find it.
  • [✔️] I searched the FastAPI documentation, with the integrated search.
  • [✔️] I already searched in Google "How to X in FastAPI" and didn't find any information.

Description

Is it possible to customise the documentation generated by fastapi when I define an UploadFile object to a POST method?

Additional context

Say for example I had a method like this where a file can be uploaded:

@router.post("/entity/new",)
async def upload_new_entity(file: UploadFile = File(...):
    return {"filename": file.filename}

This seems to generate an entry in the schemas section of the docs with the pattern of Body<func_name><path><method>

So my example above will have a Schema entry with the name:
Body_upload_new_entity_entity_new_post

The docs for UploadFile don't mention anything about OpenAPI docs.

Is it possible to specify a name for this UploadFile instead? And ideally also customise the details within the schema?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions