Skip to content

Commit

Permalink
fix: Internal error when Open API 2.0 schema contains no swagger key
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
  • Loading branch information
Stranger6667 committed Mar 1, 2024
1 parent d0898c9 commit 3e80676
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Changelog
- Not respecting ``allow_x00`` and ``codec`` configs options during filling gaps in explicit examples.
- Internal error when sending ``multipart/form-data`` requests when the schema defines the ``*/*`` content type.
- Internal error when YAML payload definition contains nested ``binary`` format.
- Internal error when an Open API 2.0 schema contains no ``swagger`` key and the schema version is forced.

**Changed**

Expand Down
5 changes: 4 additions & 1 deletion src/schemathesis/runner/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ class InternalErrorType(str, enum.Enum):
OTHER = "other"


DEFAULT_INTERNAL_ERROR_MESSAGE = "An internal error occurred during the test run"


@dataclass
class InternalError(ExecutionEvent):
"""An error that happened inside the runner."""
Expand Down Expand Up @@ -243,7 +246,7 @@ def from_exc(cls, exc: Exception) -> InternalError:
type_=InternalErrorType.OTHER,
subtype=None,
title="Test Execution Error",
message="An internal error occurred during the test run",
message=DEFAULT_INTERNAL_ERROR_MESSAGE,
extras=[],
)

Expand Down
2 changes: 1 addition & 1 deletion src/schemathesis/specs/openapi/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ class SwaggerV20(BaseOpenAPISchema):

@property
def spec_version(self) -> str:
return self.raw_schema["swagger"]
return self.raw_schema.get("swagger", "2.0")

@property
def verbose_name(self) -> str:
Expand Down
4 changes: 3 additions & 1 deletion test/cli/test_crashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from schemathesis.cli import ALL_CHECKS_NAMES, ALL_TARGETS_NAMES
from schemathesis.code_samples import CodeSampleStyle
from schemathesis.fixups import ALL_FIXUPS
from schemathesis.runner.events import DEFAULT_INTERNAL_ERROR_MESSAGE
from schemathesis.stateful import Stateful


Expand Down Expand Up @@ -132,7 +133,7 @@ def csv_strategy(enum):
@pytest.mark.usefixtures("mocked_schema")
def test_valid_parameters_combos(cli, schema_url, params, flags, multiple_params, csv_params, tmp_path):
report = tmp_path / "temp.tar.gz"
result = cli.run(schema_url, *params, *multiple_params, *flags, *csv_params, f"--report={report}")
result = cli.run(schema_url, *params, *multiple_params, *flags, *csv_params, f"--report={report}", "--show-trace")
check_result(result)


Expand All @@ -156,6 +157,7 @@ def test_schema_validity(cli, schema, base_url):

def check_result(result):
assert not (result.exception and not isinstance(result.exception, SystemExit)), result.stdout
assert DEFAULT_INTERNAL_ERROR_MESSAGE not in result.stdout, result.stdout


def test_not_handled_error(mocker, cli, schema_url):
Expand Down

0 comments on commit 3e80676

Please sign in to comment.