diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb40e5..7a0341a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.5] - 2022-12-22 :santa: +- Fixes [#22](https://github.com/Neoteroi/essentials-openapi/issues/22) + ## [1.0.4] - 2022-11-06 :snake: - Fixes [#18](https://github.com/Neoteroi/essentials-openapi/issues/18) - Workflow maintenance diff --git a/openapidocs/__init__.py b/openapidocs/__init__.py index c02d846..9d33622 100644 --- a/openapidocs/__init__.py +++ b/openapidocs/__init__.py @@ -1 +1 @@ -VERSION = "1.0.4" +VERSION = "1.0.5" diff --git a/openapidocs/mk/__init__.py b/openapidocs/mk/__init__.py index e44156f..cb47769 100644 --- a/openapidocs/mk/__init__.py +++ b/openapidocs/mk/__init__.py @@ -26,15 +26,14 @@ def read_dict(obj, *args, default=None): assert isinstance(obj, dict) value = obj - for part in args: - for key in part.split(): - if not isinstance(value, dict): - raise ValueError(f"Invalid sub-path: {repr(args)}") + for key in args: + if not isinstance(value, dict): + raise ValueError(f"Invalid sub-path: {repr(args)}") - value = value.get(key) + value = value.get(key) - if value is None: - return default + if value is None: + return default if value is None or value is obj: return default diff --git a/openapidocs/mk/v3/__init__.py b/openapidocs/mk/v3/__init__.py index f1bcc8c..d7fb513 100644 --- a/openapidocs/mk/v3/__init__.py +++ b/openapidocs/mk/v3/__init__.py @@ -184,7 +184,7 @@ def get_operations(self): return groups def get_schemas(self): - schemas = read_dict(self.doc, "components schemas") + schemas = read_dict(self.doc, "components", "schemas") if not schemas: return @@ -287,7 +287,7 @@ def get_security_scheme(self, name: str) -> dict: """ Gets a security scheme from the components section, by name. """ - security_scheme = read_dict(self.doc, "components securitySchemes") + security_scheme = read_dict(self.doc, "components", "securitySchemes") if not security_scheme: # pragma: no cover warnings.warn( @@ -536,6 +536,10 @@ def expand_references(self, schema, context: Optional[ExpandContext] = None): if is_reference(schema): return self.expand_references(self.resolve_reference(schema)) + if schema is None: + # this should not happen, but we don't want the whole build to fail + return None + clone = copy.deepcopy(schema) for key in list(clone.keys()): diff --git a/tests/test_mk.py b/tests/test_mk.py index 696621e..b69ded6 100644 --- a/tests/test_mk.py +++ b/tests/test_mk.py @@ -19,7 +19,7 @@ def test_is_array_schema(): def test_read_dict_raises_for_non_dict_property(): with pytest.raises(ValueError): - read_dict({"x": 1}, "x a") + read_dict({"x": 1}, "x", "a") def test_read_dict_default():