Skip to content

Commit

Permalink
Add description argument to Response.add_model() (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: DataGhost <[email protected]>
  • Loading branch information
DataGhost and DataGhost authored Feb 22, 2022
1 parent 6025aea commit 6daee74
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions spectree/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def __init__(
self.code_descriptions[code] = description

def add_model(
self, code: int, model: Type[BaseModel], replace: bool = True
self,
code: int,
model: Type[BaseModel],
replace: bool = True,
description: Optional[str] = None,
) -> None:
"""Add data *model* for the specified status *code*.
Expand All @@ -64,10 +68,14 @@ def add_model(
:param replace: If `True` and a data *model* already exists for the given
status *code* it will be replaced, if `False` the existing data *model*
will be retained.
:param description: The description string for the code.
"""
if not replace and self.find_model(code):
return
self.code_models[f"HTTP_{code}"] = model
code_name = f"HTTP_{code}"
self.code_models[code_name] = model
if description:
self.code_descriptions[code_name] = description

def has_model(self) -> bool:
"""
Expand Down

0 comments on commit 6daee74

Please sign in to comment.