2

I wish to create sample requests for my API documentation in Swagger UI, but I am accepting Form input.

FastAPI docs demonstrate how to do that only for Pydantic schema. Please help me with this

Can example/examples be used for Form input to create sample requests in any way?

Chris
  • 18,724
  • 6
  • 46
  • 80
Deepali
  • 31
  • 2

1 Answers1

0

You need to pass the pydantic class in api route function image

image

from fastapi import FastAPI, Form
from pydantic import BaseModel

app = FastAPI()

class request_json(BaseModel):
    name:str
    age:int
    mail:str
        
@app.get("/name")
async def get_values(
    reqest_model:request_json,
    username: Annotated[str, Form()],
    password: Annotated[str, Form()]
):
    responce_dict = {"name":reqest_model.name, "username": username}}
    return responce_dict
SternK
  • 11,649
  • 22
  • 32
  • 46
Deepak
  • 1
  • 1