Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions chalice_spec/chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
from pydantic import BaseModel


class EmptyModel(BaseModel):
pass


def default_docs_for_methods(
methods: List[str], content_types: Optional[List[str]] = None
):
Expand All @@ -22,11 +26,11 @@ def default_docs_for_methods(
**{
method: Operation(
content_types=content_types,
response=BaseModel,
response=EmptyModel,
request=(
None
if method in ["get", "delete", "head", "options"]
else BaseModel
else EmptyModel
),
)
for method in methods
Expand Down
19 changes: 10 additions & 9 deletions chalice_spec/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ def schema_helper(

# If the spec has passed, we probably have nested models to contend with.
spec: Union[APISpec, None] = kwargs.pop("spec", None)
if spec and "definitions" in schema:
for k, v in schema["definitions"].items():
try:
spec.components.schema(k, v)
except DuplicateComponentNameError:
pass

if "definitions" in schema:
del schema["definitions"]
for key in ("definitions", "$defs"):
if spec and key in schema:
for k, v in schema[key].items():
try:
spec.components.schema(k, v)
except DuplicateComponentNameError:
pass

if key in schema:
del schema[key]

return schema

Expand Down
6 changes: 3 additions & 3 deletions tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_blueprint_three_with_default_docs():
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {"$ref": "#/components/schemas/BaseModel"}
"schema": {"$ref": "#/components/schemas/EmptyModel"}
}
}
},
Expand All @@ -148,7 +148,7 @@ def test_blueprint_three_with_default_docs():
"description": "Success",
"content": {
"application/json": {
"schema": {"$ref": "#/components/schemas/BaseModel"}
"schema": {"$ref": "#/components/schemas/EmptyModel"}
}
},
}
Expand All @@ -160,7 +160,7 @@ def test_blueprint_three_with_default_docs():
"openapi": "3.0.1",
"components": {
"schemas": {
"BaseModel": {"title": "BaseModel", "type": "object", "properties": {}}
"EmptyModel": {"title": "EmptyModel", "type": "object", "properties": {}}
}
},
}
Expand Down