diff --git a/src/check_jsonschema/checker.py b/src/check_jsonschema/checker.py index 1ecb9c86a..e088ee5b0 100644 --- a/src/check_jsonschema/checker.py +++ b/src/check_jsonschema/checker.py @@ -67,9 +67,11 @@ def _build_result(self) -> CheckResult: if isinstance(data, ParseError): result.record_parse_error(path, data) else: - validator = self.get_validator(path, data) - for err in validator.iter_errors(data): - result.record_validation_error(path, err) + data_list = data if isinstance(data, list) else [data] + for data in data_list: + validator = self.get_validator(path, data) + for err in validator.iter_errors(data): + result.record_validation_error(path, err) return result def _run(self) -> None: diff --git a/src/check_jsonschema/instance_loader.py b/src/check_jsonschema/instance_loader.py index 54d92acab..691bae2b5 100644 --- a/src/check_jsonschema/instance_loader.py +++ b/src/check_jsonschema/instance_loader.py @@ -1,6 +1,7 @@ from __future__ import annotations import pathlib +import types import typing as t from .parsers import ParseError, ParserSet @@ -32,5 +33,7 @@ def iter_files(self) -> t.Iterator[tuple[pathlib.Path, ParseError | t.Any]]: except ParseError as err: data = err else: + if isinstance(data, types.GeneratorType): + data = list(data) data = self._data_transform(data) yield (path, data) diff --git a/src/check_jsonschema/parsers/__init__.py b/src/check_jsonschema/parsers/__init__.py index eedb406ff..df4c93ed2 100644 --- a/src/check_jsonschema/parsers/__init__.py +++ b/src/check_jsonschema/parsers/__init__.py @@ -68,7 +68,6 @@ def get( self, path: pathlib.Path, default_filetype: str ) -> t.Callable[[t.BinaryIO], t.Any]: filetype = path_to_type(path, default_type=default_filetype) - if filetype in self._by_tag: return self._by_tag[filetype] diff --git a/src/check_jsonschema/parsers/yaml.py b/src/check_jsonschema/parsers/yaml.py index c44a032bd..6ffed6491 100644 --- a/src/check_jsonschema/parsers/yaml.py +++ b/src/check_jsonschema/parsers/yaml.py @@ -64,6 +64,15 @@ def load(stream: t.BinaryIO) -> t.Any: try: data = impl.load(stream_bytes) except ruamel.yaml.YAMLError as e: + if isinstance( + e, ruamel.yaml.composer.ComposerError + ) and "expected a single document in the stream" in str(e): + try: + data = impl.load_all(stream_bytes) + except ruamel.yaml.YAMLError as e: + lasterr = e + else: + break lasterr = e else: break diff --git a/src/check_jsonschema/schema_loader/readers.py b/src/check_jsonschema/schema_loader/readers.py index 0f9ec9185..70a4ee392 100644 --- a/src/check_jsonschema/schema_loader/readers.py +++ b/src/check_jsonschema/schema_loader/readers.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +import types import typing as t import ruamel.yaml @@ -19,7 +20,9 @@ def _run_load_callback(schema_location: str, callback: t.Callable) -> dict: # only local loads can raise the YAMLError, but catch for both cases for simplicity except (ValueError, ruamel.yaml.error.YAMLError) as e: raise SchemaParseError(schema_location) from e - if not isinstance(schema, dict): + if isinstance(schema, types.GeneratorType): + schema = list(schema) + if not isinstance(schema, dict) and not isinstance(schema, list): raise SchemaParseError(schema_location) return schema