Skip to content

Commit

Permalink
Fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored Dec 22, 2022
1 parent ffa59cb commit f879a92
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openapidocs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.0.4"
VERSION = "1.0.5"
13 changes: 6 additions & 7 deletions openapidocs/mk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions openapidocs/mk/v3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit f879a92

Please sign in to comment.