✨ Add support for extensions and updates to the OpenAPI schema in path operations (#1922)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Edouard Lavery-Plante
2021-07-29 16:01:13 -04:00
committed by GitHub
parent 7db359182d
commit 836bb97a2d
13 changed files with 487 additions and 1 deletions
@@ -0,0 +1,41 @@
from fastapi import FastAPI, Request
app = FastAPI()
def magic_data_reader(raw_body: bytes):
return {
"size": len(raw_body),
"content": {
"name": "Maaaagic",
"price": 42,
"description": "Just kiddin', no magic here. ✨",
},
}
@app.post(
"/items/",
openapi_extra={
"requestBody": {
"content": {
"application/json": {
"schema": {
"required": ["name", "price"],
"type": "object",
"properties": {
"name": {"type": "string"},
"price": {"type": "number"},
"description": {"type": "string"},
},
}
}
},
"required": True,
},
},
)
async def create_item(request: Request):
raw_body = await request.body()
data = magic_data_reader(raw_body)
return data