Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.16.2

* Fix empty response body.

## Version 0.16.1

* Fix headers validating.
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]

Expand Down
6 changes: 5 additions & 1 deletion src/schema_first/query/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = {
Expand Down
7 changes: 6 additions & 1 deletion tests/test_query_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading