Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.7k
Comments
Conversation
Codecov Report
@@ Coverage Diff @@## master #97 +/- ##========================================- Coverage 100% 99.2% -0.8%======================================== Files 109 110 +1 Lines 2740 2877 +137 ========================================+ Hits 2740 2854 +114- Misses 0 23 +23
Continue to review full report at Codecov.
|
codecovbot commentedMar 22, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## master #97 +/- ##====================================== Coverage 100% 100% ====================================== Files 109 146 +37 Lines 2740 3590 +850 ======================================+ Hits 2740 3590 +850
Continue to review full report at Codecov.
|
tiangolo commentedMar 29, 2019
Thanks! I'll review it soon. |
tiangolo commentedApr 5, 2019
Thanks@barsi, I see you put quite some effort into this, thanks for that! 👏 🍰 I took it further and updated/refactored it all to make it simpler for developers to use while extending the capabilities. For example, it's possible to add more info to an existing I also included docs, tests for the code in the docs, etc. With this you can now add a fromfastapiimportFastAPIfrompydanticimportBaseModelfromstarlette.responsesimportJSONResponseclassItem(BaseModel):id:strvalue:strclassMessage(BaseModel):message:strapp=FastAPI()@app.get("/items/{item_id}",response_model=Item,responses={404: {"model":Message}})asyncdefread_item(item_id:str):ifitem_id=="foo":return {"id":"foo","value":"there goes my hero"}else:returnJSONResponse(status_code=404,content={"message":"Item not found"}) The new docs are here:https://fastapi.tiangolo.com/tutorial/additional-responses/ |
barsi commentedApr 5, 2019
@tiangolo Thanks for the brilliant & carefully crafted framework 🥇 , glad to be a contributor 👍 |
tiangolo commentedApr 5, 2019
Thanks! 😊 🌮 🍰 |
Signed-off-by lmignon
Additional Responses Support
Summary
allows additional responses to be defined beside the default one
Example
Result
you can also define additional responses on
app.include_routerso it can save you from repeating the definition of common response types (e.g.HTTP 500)Limitations
This pull request only implements the injection of
additional responses definitions into OpenAPI schema
to be appeared in swagger or other OpenAPI 3 compatible
clients (e.g. postman), here are some of the limitations:
headers&examples).