Skip to content
Open
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
9 changes: 7 additions & 2 deletions openapi_spec_validator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def main(args: Sequence[str] | None = None) -> None:
schemas.get_validator_backend() != "jsonschema-rs"
)

read_failed = False
for filename in args_parsed.file:
# choose source
reader = read_from_filename
Expand All @@ -163,8 +164,9 @@ def main(args: Sequence[str] | None = None) -> None:
try:
spec, base_uri = reader(filename)
except Exception as exc:
print(exc)
sys.exit(1)
print_error(filename, exc)
read_failed = True
continue

# choose the validator
validators: dict[str, type[SpecValidator] | None] = {
Expand Down Expand Up @@ -218,6 +220,9 @@ def main(args: Sequence[str] | None = None) -> None:
else:
print_ok(filename)

if read_failed:
sys.exit(1)


if __name__ == "__main__":
main()
14 changes: 14 additions & 0 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ def test_nonexisting_file(capsys):
assert "No such file: i_dont_exist.yaml\n" in out


def test_read_error_names_file_and_continues(capsys):
"""A file that cannot be read is named and does not stop the rest."""
testargs = [
"i_dont_exist.yaml",
"./tests/integration/data/v3.1/petstore.yaml",
]
with pytest.raises(SystemExit):
main(testargs)
out, err = capsys.readouterr()
assert not err
assert "i_dont_exist.yaml: Error: No such file: i_dont_exist.yaml\n" in out
assert "./tests/integration/data/v3.1/petstore.yaml: OK\n" in out


def test_schema_stdin(capsys):
"""Test schema from STDIN"""
spes_path = "./tests/integration/data/v3.0/petstore.yaml"
Expand Down