-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from rominf/rominf/add_additional_responses
Add additional responses
- Loading branch information
Showing
11 changed files
with
306 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
.../expected/openapi/default_template/same_response_model_for_different_status_codes/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# generated by fastapi-codegen: | ||
# filename: same_response_model_for_different_status_codes.yaml | ||
# timestamp: 2020-06-19T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Optional, Union | ||
|
||
from fastapi import FastAPI, Path | ||
|
||
from .models import Error, Pets | ||
|
||
app = FastAPI( | ||
version='1.0.0', | ||
title='Swagger Petstore', | ||
license={'name': 'MIT'}, | ||
description='This description is for testing\nmulti-line\ndescription\n', | ||
) | ||
|
||
|
||
@app.get('/pets', response_model=Pets, responses={'default': {'model': Error}}) | ||
def list_pets(limit: Optional[int] = None) -> Union[Pets, Error]: | ||
""" | ||
List all pets | ||
""" | ||
pass | ||
|
||
|
||
@app.post('/pets', response_model=None, responses={'default': {'model': Error}}) | ||
def create_pets() -> Union[None, Error]: | ||
""" | ||
Create a pet | ||
""" | ||
pass | ||
|
||
|
||
@app.get( | ||
'/pets/{pet_id}', | ||
response_model=Pets, | ||
responses={'404': {'model': Error}, 'default': {'model': Error}}, | ||
) | ||
def show_pet_by_id(pet_id: str = Path(..., alias='petId')) -> Union[Pets, Error]: | ||
""" | ||
Info for a specific pet | ||
""" | ||
pass |
24 changes: 24 additions & 0 deletions
24
...xpected/openapi/default_template/same_response_model_for_different_status_codes/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# generated by fastapi-codegen: | ||
# filename: same_response_model_for_different_status_codes.yaml | ||
# timestamp: 2020-06-19T00:00:00+00:00 | ||
|
||
from __future__ import annotations | ||
|
||
from typing import List, Optional | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class Pet(BaseModel): | ||
id: int | ||
name: str | ||
tag: Optional[str] = None | ||
|
||
|
||
class Pets(BaseModel): | ||
__root__: List[Pet] = Field(..., description='list of pet') | ||
|
||
|
||
class Error(BaseModel): | ||
code: int | ||
message: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.