fastapi
fastapi copied to clipboard
Consider warning about misuse of query parameters with BaseModel
I've noticed several times, especially for new users - a common mistake is to put for a in a GET request with query parameters, a BaseModel
type annotation, causing the OpenAPI docs to miss the parameter entirely.
Consider the following code:
from pydantic import BaseModel
from fastapi import FastAPI
class UserDetails(BaseModel):
username: str
full_name: str
api = FastAPI()
@api.get('/user-details')
def get_user_details(details: UserDetails):
pass
The rendered OpenAPI documentation parameters is empty:
Is this something that would be worth solving? I think it would ease the on-boarding of new users. I can think of two solutions:
- Printing a warning message in debug mode when that usage is detected.
- Throwing an exception? probably too intrusive.
What do yo think? would be happy to implement the solution.