Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeauriach committed Sep 25, 2023
1 parent 9cb292d commit ee3559a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 13 additions & 3 deletions chalice_spec/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ class Response:
and an optional description.
"""

def __init__(self, model: type, code: int = 200, description: str = "Success", content_type: str = DEFAULT_CONTENT_TYPE):
def __init__(
self,
model: type,
code: int = 200,
description: str = "Success",
content_type: str = DEFAULT_CONTENT_TYPE
):
self.model = model
self.code = code
self.description = description
Expand Down Expand Up @@ -64,15 +70,19 @@ def _populate_response(self, response: Union[Response, type]):
self.responses = {response.code: {DEFAULT_CONTENT_TYPE: response}}
else:
# If not, we will use sensible defaults
self.responses = {DEFAULT_CODE: {DEFAULT_CONTENT_TYPE: Response(model=response)}}
self.responses = {
DEFAULT_CODE: {DEFAULT_CONTENT_TYPE: Response(model=response)}
}

def _populate_responses(self, responses: List[Response]):
self.responses = {}
for response in responses:
if response.code not in self.responses:
self.responses[response.code] = {}
if response.content_type in self.responses[response.code]:
raise TypeError(f"Multiple responses defined for {response.code}{response.content_type}")
raise TypeError(
f"Multiple responses defined for {response.code}{response.content_type}"
)
self.responses[response.code][response.content_type] = response


Expand Down
8 changes: 7 additions & 1 deletion tests/test_chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,13 @@ def test_content_types():
"/posts",
methods=["POST"],
content_types=["multipart/form-data"],
docs=Docs(request=TestSchema, responses=[Resp(model=AnotherSchema, content_type="application/json"), Resp(model=AnotherSchema, content_type="application/xml")]),
docs=Docs(
request=TestSchema,
responses=[
Resp(model=AnotherSchema, content_type="application/json"),
Resp(model=AnotherSchema, content_type="application/xml")
],
),
)
def get_post():
pass
Expand Down

0 comments on commit ee3559a

Please sign in to comment.