Skip to content

Commit

Permalink
fix: Internal error when media type definition has no schema
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
  • Loading branch information
Stranger6667 committed May 11, 2024
1 parent 2d2dc79 commit 2a30118
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
**Fixed**

- Internal error on unresolvable Open API links during stateful testing.
- Internal error when media type definition has only ``example`` or ``examples`` keys.

**Performance**

Expand Down
4 changes: 2 additions & 2 deletions src/schemathesis/specs/openapi/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,11 +1066,11 @@ def prepare_multipart(
for media_type, entry in content.items():
main, sub = parse_content_type(media_type)
if main in ("*", "multipart") and sub in ("*", "form-data", "mixed"):
schema = entry["schema"]
schema = entry.get("schema")
break
else:
raise InternalError("No 'multipart/form-data' media type found in the schema")
for name, property_schema in schema.get("properties", {}).items():
for name, property_schema in (schema or {}).get("properties", {}).items():
if name in form_data:
if isinstance(form_data[name], list):
files.extend([(name, item) for item in form_data[name]])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Exit code: 0
---
Stdout:
======================= Schemathesis test session starts =======================
Schema location: file:///tmp/schema.json
Base URL: http://127.0.0.1/api
Specification version: Open API 3.0.0
Random seed: 42
Workers: 1
Collected API operations: 1
Collected API links: 0
API probing: SUCCESS
Schema analysis: SKIP

POST /api/property . [100%]

=================================== SUMMARY ====================================

Performed checks:
not_a_server_error 1 / 1 passed PASSED

WARNING: All API responses have a 404 status code. Did you specify the proper API location?

Tip: Use the `--report` CLI option to visualize test results via Schemathesis.io.
We run additional conformance checks on reports from public repos.

============================== 1 passed in 1.00s ===============================
30 changes: 30 additions & 0 deletions test/cli/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,36 @@ def decode(idx):
# NOTE, that the actual API operation is not checked in this test


@pytest.mark.openapi_version("3.0")
def test_no_schema_in_media_type(testdir, cli, base_url, snapshot_cli):
schema = {
"openapi": "3.0.0",
"info": {"title": "Sample API", "description": "API description in Markdown.", "version": "1.0.0"},
"paths": {
"/property": {
"post": {
"requestBody": {
"required": True,
"content": {"multipart/form-data": {}},
},
"responses": {"200": {"description": "OK"}},
}
},
},
}
schema_file = testdir.make_openapi_schema_file(schema)
assert (
cli.run(
str(schema_file),
f"--base-url={base_url}",
"--hypothesis-max-examples=1",
"--show-trace",
"--validate-schema=true",
)
== snapshot_cli
)


def test_nested_binary_in_yaml(testdir, openapi3_base_url, cli, snapshot_cli, empty_open_api_3_schema):
empty_open_api_3_schema["paths"] = {
"/property": {
Expand Down

0 comments on commit 2a30118

Please sign in to comment.