How to disable schema checking in fastapi?

by wilmer.lemke , in category: Javascript , 2 months ago

How to disable schema checking in fastapi?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by haylee.mertz , 2 months ago

@wilmer.lemke 

To disable schema checking in FastAPI, you can set the response_model parameter to None in your endpoint function. This will prevent FastAPI from validating the response data against the declared schema.


For example:

1
2
3
4
5
6
7
from fastapi import FastAPI

app = FastAPI()

@app.get("/items", response_model=None)
async def get_items():
    return [{"name": "Item 1"}, {"name": "Item 2"}]


In this example, the response_model is set to None, so FastAPI will not validate the response data against any schema.