diff --git a/chalice_spec/chalice.py b/chalice_spec/chalice.py index aa55781..76636e7 100644 --- a/chalice_spec/chalice.py +++ b/chalice_spec/chalice.py @@ -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 ): @@ -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 diff --git a/chalice_spec/pydantic.py b/chalice_spec/pydantic.py index 6f17815..0935983 100644 --- a/chalice_spec/pydantic.py +++ b/chalice_spec/pydantic.py @@ -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 diff --git a/tests/test_blueprint.py b/tests/test_blueprint.py index 5f6b1d2..0739563 100644 --- a/tests/test_blueprint.py +++ b/tests/test_blueprint.py @@ -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"} } } }, @@ -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"} } }, } @@ -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": {}} } }, }