diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 97298a9..dd95519 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: hooks: - id: unkey - repo: https://github.com/pycqa/isort - rev: 9.0.0b1 + rev: 9.0.0b2 hooks: - id: isort - repo: https://github.com/hauntsaninja/no_implicit_optional diff --git a/CHANGES.md b/CHANGES.md index ee91ab8..4530755 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +## Version 0.16.2 + +* Fix empty response body. + ## Version 0.16.1 * Fix headers validating. diff --git a/pyproject.toml b/pyproject.toml index af1ec09..b1334b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,18 +20,18 @@ license-files = ["LICENSE.txt"] name = "Schema-First" readme = "README.md" requires-python = ">=3.12" -version = "0.16.1" +version = "0.16.2" [project.optional-dependencies] dev = [ "bandit>=1.9.3", "build>=1.4.0", 'openapi-spec-validator>=0.7.1', - "pre-commit>=4.5.1", + "pre-commit>=4.6.2", "pytest>=9.1.1", "pytest-cov>=7.0.0", "python-dotenv>=1.2.1", - "tox==4.18.0", + "tox==4.59.0", "twine==6.2.0" ] diff --git a/src/schema_first/query/validator.py b/src/schema_first/query/validator.py index 9533f11..c153bc6 100644 --- a/src/schema_first/query/validator.py +++ b/src/schema_first/query/validator.py @@ -85,6 +85,10 @@ def _make_schema_for_response(self, **data: dict[str, t.Any]) -> type[Schema]: body_schema = content_type.get('schema') if body_schema: response_fields['body'] = fields.Nested(body_schema) + else: + # If body must be empty. + if data.get('content_type'): + response_fields['content_type'] = fields.String() response_schema = Schema.from_dict(response_fields) response_schema.Meta.unknown = 'raise' @@ -128,7 +132,7 @@ def response_handler( endpoint: str, method: t.Literal['post', 'get', 'update', 'patch', 'delete'], status_code: str, - content_type: t.Literal['application/json'] or ... = ..., + content_type: str or ... = ..., body: dict[str, t.Any] or ... = ..., ): all_kwargs = { diff --git a/tests/test_query_validators.py b/tests/test_query_validators.py index 8f08c25..789bc5f 100644 --- a/tests/test_query_validators.py +++ b/tests/test_query_validators.py @@ -166,7 +166,12 @@ def test_query_validators__response__empty_body_in_spec(fx_openapi_3_2_0, fx_ope spec = fx_open_spec(file_path) query_validator = HTTPQueryValidator(spec) - request = {'endpoint': '/endpoint', 'method': 'get', 'status_code': '204'} + request = { + 'endpoint': '/endpoint', + 'method': 'get', + 'content_type': 'application/json', + 'status_code': '204', + } serialized_request = query_validator.response_handler(**request)