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

OpenAPI Example with multipart/form-data not showing up #10999

Open
9 tasks done
Kludex opened this issue Jan 21, 2024 Discussed in #10937 · 5 comments
Open
9 tasks done

OpenAPI Example with multipart/form-data not showing up #10999

Kludex opened this issue Jan 21, 2024 Discussed in #10937 · 5 comments
Labels
bug Something isn't working

Comments

@Kludex
Copy link
Sponsor Collaborator

Kludex commented Jan 21, 2024

Discussed in #10937

Originally posted by SeeRich January 11, 2024

First Check

  • I added a very descriptive title here.
  • I used the GitHub search to find a similar question 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.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Annotated
from fastapi import FastAPI, UploadFile, Form, File

# Run using uvicorn main:app --reload
# Visit: http://127.0.0.1:8000/docs

app = FastAPI()

@app.post("/form-test")
async def form_test(
        str_data: Annotated[str, Form(examples=["HELLO"])],
        file: Annotated[UploadFile, File()]):
    return

Description

The HELLO example is not shown in the docs.

fastapi

Operating System

Windows

Operating System Details

No response

FastAPI Version

0.108.0

Pydantic Version

2.5.3

Python Version

3.11.3

Additional Context

No response

@Kludex Kludex added the question Question or problem label Jan 21, 2024
@Kludex
Copy link
Sponsor Collaborator Author

Kludex commented Jan 21, 2024

Using json_schema_extra works as expected:

from typing import Annotated
from fastapi import FastAPI, UploadFile, Form, File

# Run using uvicorn main:app --reload
# Visit: http://127.0.0.1:8000/docs

app = FastAPI()


@app.post("/form-test")
async def form_test(
    str_data: Annotated[str, Form(json_schema_extra={"example": "test"})],
    file: Annotated[UploadFile, File()],
):
    return

But using only Form(example=...) doesn't.

@Kludex Kludex added bug Something isn't working and removed question Question or problem labels Jan 21, 2024
@ThirVondukr
Copy link

@Kludex Alias in File(alias="someAlias") doesn't seem to work either, just ran into this in my codebase 🤔

@Kludex
Copy link
Sponsor Collaborator Author

Kludex commented Feb 9, 2024

@Kludex Alias in File(alias="someAlias") doesn't seem to work either, just ran into this in my codebase 🤔

@ThirVondukr
Copy link

Seems like currently you can specify json_schema_extra={"alias": alias} as a workaround

@jean0t
Copy link

jean0t commented Apr 19, 2024

If you use Forms the way you first did, it will end up in the **extra part of arguments, kwargs basically. But it is also stated in the code that this option is deprecated and also recommends to use json_schema_extra instead.
Screenshot from 2024-04-19 20-52-45

what you found might be an error because of that, so just stick to the recommended :)
if you want to see more about it, just go to the file param_functions.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants