Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored May 5, 2022
1 parent 9d8a8e0 commit 7f5e1a9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ 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.1] - 2022-??-??
## [1.0.1] - 2022-05-05
- Adds a new output style, to provide an overview of the API endpoints with
PlantUML
- Fixes two bugs caused by improper handling of OpenAPI Documentation without
`components` https://github.com/Neoteroi/mkdocs-plugins/issues/9

## [1.0.0] - 2022-04-20 :sparkles:
- Adds features and a CLI to generate artifacts from OpenAPI Documentation
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.0"
VERSION = "1.0.1"
11 changes: 10 additions & 1 deletion openapidocs/mk/v3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ def __init__(
writer: Optional[DocumentsWriter] = None,
style: Union[int, str] = 1,
) -> None:
self.doc = copy.deepcopy(doc)
self.doc = self.normalize_data(copy.deepcopy(doc))
self.texts = texts or EnglishTexts()
self._writer = writer or Jinja2DocumentsWriter(
__name__, views_style=style_from_value(style)
)

def normalize_data(self, data):
"""
Applies corrections to the OpenAPI specification, to simplify its handling.
"""
if "components" not in data:
data["components"] = {}

return data

def get_operations(self):
"""
Gets a dictionary of operations grouped by tag.
Expand Down
2 changes: 2 additions & 0 deletions openapidocs/mk/v3/views_markdown/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{%- include "partial/path-items.html" %}

---
{%- if components %}
{%- if components.schemas %}
{% include "partial/components-schemas.html" %}
{% endif -%}
Expand All @@ -29,3 +30,4 @@
{%- if components.securitySchemes %}
{% include "partial/components-security-schemes.html" %}
{% endif -%}
{% endif -%}
2 changes: 2 additions & 0 deletions openapidocs/mk/v3/views_mkdocs/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{% include "partial/path-items.html" %}

---
{%- if components %}
{%- if components.schemas %}
{% include "partial/components-schemas.html" %}
{% endif -%}
Expand All @@ -29,3 +30,4 @@
{%- if components.securitySchemes %}
{% include "partial/components-security-schemes.html" %}
{% endif -%}
{% endif -%}
28 changes: 28 additions & 0 deletions tests/test_mk_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,31 @@ def test_iter_bindings_arrays():
def test_style_from_value_raises_value_error():
with pytest.raises(ValueError):
style_from_value("WRONG")


def test_v3_markdown_gen_handles_missing_components():
data = {
"openapi": "3.0.0",
"info": {
"version": "1.0.0",
"title": "Example",
},
"paths": {
"/foo": {
"get": {
"responses": {
"200": {
"description": "Foo",
"content": {"text/plain": {"schema": {"type": "string"}}},
},
},
},
},
},
}
handler = OpenAPIV3DocumentationHandler(data)

html = handler.write(data)
with open("___a.html", encoding="utf8", mode="wt") as f:
f.write(html)
assert html is not None

0 comments on commit 7f5e1a9

Please sign in to comment.