File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,9 +5,11 @@ All notable changes to this project will be documented in this file.
55The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
66and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
77
8- ## [ 1.0.1] - 2022-??-??
8+ ## [ 1.0.1] - 2022-05-05
99- Adds a new output style, to provide an overview of the API endpoints with
1010 PlantUML
11+ - Fixes two bugs caused by improper handling of OpenAPI Documentation without
12+ ` components ` https://github.com/Neoteroi/mkdocs-plugins/issues/9
1113
1214## [ 1.0.0] - 2022-04-20 :sparkles :
1315- Adds features and a CLI to generate artifacts from OpenAPI Documentation
Original file line number Diff line number Diff line change 1- VERSION = "1.0.0 "
1+ VERSION = "1.0.1 "
Original file line number Diff line number Diff line change @@ -74,12 +74,21 @@ def __init__(
7474 writer : Optional [DocumentsWriter ] = None ,
7575 style : Union [int , str ] = 1 ,
7676 ) -> None :
77- self .doc = copy .deepcopy (doc )
77+ self .doc = self . normalize_data ( copy .deepcopy (doc ) )
7878 self .texts = texts or EnglishTexts ()
7979 self ._writer = writer or Jinja2DocumentsWriter (
8080 __name__ , views_style = style_from_value (style )
8181 )
8282
83+ def normalize_data (self , data ):
84+ """
85+ Applies corrections to the OpenAPI specification, to simplify its handling.
86+ """
87+ if "components" not in data :
88+ data ["components" ] = {}
89+
90+ return data
91+
8392 def get_operations (self ):
8493 """
8594 Gets a dictionary of operations grouped by tag.
Original file line number Diff line number Diff line change 1414{%- include "partial/path-items.html" %}
1515
1616---
17+ {%- if components %}
1718{%- if components.schemas %}
1819{% include "partial/components-schemas.html" %}
1920{% endif -%}
2930{%- if components.securitySchemes %}
3031{% include "partial/components-security-schemes.html" %}
3132{% endif -%}
33+ {% endif -%}
Original file line number Diff line number Diff line change 1414{% include "partial/path-items.html" %}
1515
1616---
17+ {%- if components %}
1718{%- if components.schemas %}
1819{% include "partial/components-schemas.html" %}
1920{% endif -%}
2930{%- if components.securitySchemes %}
3031{% include "partial/components-security-schemes.html" %}
3132{% endif -%}
33+ {% endif -%}
Original file line number Diff line number Diff line change @@ -222,3 +222,31 @@ def test_iter_bindings_arrays():
222222def test_style_from_value_raises_value_error ():
223223 with pytest .raises (ValueError ):
224224 style_from_value ("WRONG" )
225+
226+
227+ def test_v3_markdown_gen_handles_missing_components ():
228+ data = {
229+ "openapi" : "3.0.0" ,
230+ "info" : {
231+ "version" : "1.0.0" ,
232+ "title" : "Example" ,
233+ },
234+ "paths" : {
235+ "/foo" : {
236+ "get" : {
237+ "responses" : {
238+ "200" : {
239+ "description" : "Foo" ,
240+ "content" : {"text/plain" : {"schema" : {"type" : "string" }}},
241+ },
242+ },
243+ },
244+ },
245+ },
246+ }
247+ handler = OpenAPIV3DocumentationHandler (data )
248+
249+ html = handler .write (data )
250+ with open ("___a.html" , encoding = "utf8" , mode = "wt" ) as f :
251+ f .write (html )
252+ assert html is not None
You can’t perform that action at this time.
0 commit comments