Skip to content

Commit c70519b

Browse files
v1.0.6 🐌
1 parent da1d024 commit c70519b

File tree

11 files changed

+201
-5
lines changed

11 files changed

+201
-5
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [1.0.6] - 2023-03-18
8+
## [1.0.6] - 2023-03-19 :snail:
99
- Fixes a bug happening when trying to serialize examples in JSON, when they
10-
contain datetimes and are provided in YAML.
10+
contain datetimes and are provided in YAML;
1111
([bug report](https://github.com/Neoteroi/mkdocs-plugins/issues/35)).
12+
- Fixes a bug related to missing resolution of references for `requestBody`;
13+
([bug report](https://github.com/Neoteroi/essentials-openapi/issues/21)).
14+
- Fixes support for code fences (disables by default `autoescape`, since the
15+
source of OpenAPI Specification files is supposed to be trusted anyway.
16+
Those who still wants to have `autoescape` enabled with `Jinja` can do so
17+
setting an environment variable: `SELECT_AUTOESCAPE=1`.
18+
([bug report](https://github.com/Neoteroi/essentials-openapi/issues/24)).
1219

1320
## [1.0.5] - 2022-12-22 :santa:
1421
- Fixes [#22](https://github.com/Neoteroi/essentials-openapi/issues/22)

openapidocs/mk/jinja.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
2-
This module provides a Jinja2 environment to
2+
This module provides a Jinja2 environment.
33
"""
4+
import os
45
from enum import Enum
56

67
from jinja2 import Environment, PackageLoader, Template, select_autoescape
@@ -74,7 +75,9 @@ def get_environment(
7475
else:
7576
env = Environment(
7677
loader=loader,
77-
autoescape=select_autoescape(["html", "xml"]),
78+
autoescape=select_autoescape(["html", "xml"])
79+
if os.environ.get("SELECT_AUTOESCAPE") in {"YES", "Y", "1"}
80+
else False,
7881
auto_reload=True,
7982
enable_async=False,
8083
)

openapidocs/mk/v3/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ def get_operations(self):
179179

180180
for path, path_item in paths.items():
181181
tag = self.get_tag(path_item) or ""
182+
183+
for operation in path_item.values():
184+
# need to resolve possible references for requestBody
185+
if "requestBody" in operation:
186+
operation["requestBody"] = self._resolve_opt_ref(
187+
operation["requestBody"]
188+
)
189+
182190
groups[tag].append((path, path_item))
183191

184192
return groups

openapidocs/mk/v3/views_markdown/partial/path-items.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
{% include "partial/request-body.html" %}
2929
{%- endif %}
3030

31+
{%- if operation.responses %}
3132
{%- include "partial/request-responses.html" %}
33+
{%- endif %}
3234
{%- endfor -%}
3335
{%- endfor -%}
3436
{%- endfor -%}

openapidocs/mk/v3/views_mkdocs/partial/path-items.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
{% include "partial/request-body.html" %}
2727
{%- endif %}
2828

29+
{%- if operation.responses %}
2930
{%- include "partial/request-responses.html" %}
31+
{%- endif %}
3032
{% endfor %}
3133
{% endfor %}
3234
{% endfor %}

tests/res/example4-split-output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Retrieve all users
195195
<td>string</td>
196196
<td></td>
197197
<td>No</td>
198-
<td>Paginate through users by setting the cursor parameter to a nextCursor attribute returned by a previous request&#39;s response. Default value fetches the first &#34;page&#34; of the collection. See pagination for more detail.</td>
198+
<td>Paginate through users by setting the cursor parameter to a nextCursor attribute returned by a previous request's response. Default value fetches the first "page" of the collection. See pagination for more detail.</td>
199199
</tr>
200200
<tr>
201201
<td class="parameter-name"><code>limit</code></td>

tests/res/example6-openapi.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Example with requestBody component, see https://github.com/Neoteroi/essentials-openapi/issues/21
2+
openapi: 3.0.1
3+
info:
4+
title: Test
5+
version: v1
6+
paths:
7+
"/something":
8+
post:
9+
requestBody:
10+
$ref: "#/components/requestBodies/SomeBody"
11+
components:
12+
requestBodies:
13+
SomeBody:
14+
description: Foo Bar.
15+
required: true
16+
content:
17+
application/json:
18+
schema:
19+
type: object
20+
properties:
21+
a:
22+
type: string

tests/res/example6-output.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!--
2+
This Markdown has been generated by essentials-openapi
3+
https://github.com/Neoteroi/essentials-openapi
4+
5+
Most likely, it is not desirable to edit this file by hand!
6+
-->
7+
8+
# Test <span class="api-version">v1</span>
9+
10+
11+
## <span class="api-tag"></span>
12+
13+
<hr class="operation-separator" />
14+
15+
### <span class="http-post">POST</span> /something
16+
17+
<p class="request-body-title"><strong>Request body</strong></p>
18+
19+
20+
21+
=== "application/json"
22+
23+
24+
```json
25+
{
26+
"a": "string"
27+
}
28+
```
29+
<span class="small-note">⚠️</span>&nbsp;<em class="small-note warning">This example has been generated automatically from the schema and it is not accurate. Refer to the schema for more information.</em>
30+
31+
32+
33+
??? hint "Schema of the request body"
34+
```json
35+
{
36+
"type": "object",
37+
"properties": {
38+
"a": {
39+
"type": "string"
40+
}
41+
}
42+
}
43+
```
44+
45+
46+
47+
48+
49+
50+
---

tests/res/example7-openapi.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# https://github.com/Neoteroi/essentials-openapi/issues/24
2+
openapi: "3.0.2"
3+
info:
4+
title: API Title
5+
description: |
6+
**Response**
7+
8+
```json
9+
[
10+
{
11+
"a": "b",
12+
"c": {
13+
"d": "e"
14+
}
15+
}
16+
]
17+
```
18+
version: "1.0"
19+
servers:
20+
- url: https://api.server.test/v1
21+
paths:
22+
/test:
23+
get:
24+
responses:
25+
'200':
26+
description: OK

tests/res/example7-output.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!--
2+
This Markdown has been generated by essentials-openapi
3+
https://github.com/Neoteroi/essentials-openapi
4+
5+
Most likely, it is not desirable to edit this file by hand!
6+
-->
7+
8+
# API Title <span class="api-version">1.0</span>
9+
10+
**Response**
11+
12+
```json
13+
[
14+
{
15+
"a": "b",
16+
"c": {
17+
"d": "e"
18+
}
19+
}
20+
]
21+
```
22+
<hr />
23+
## Servers
24+
25+
<table>
26+
<thead>
27+
<tr>
28+
<th>Description</th>
29+
<th>URL</th>
30+
</tr>
31+
</thead>
32+
<tbody>
33+
<tr>
34+
<td>https://api.server.test/v1</td>
35+
<td>
36+
<a href="https://api.server.test/v1" target="_blank" rel="noopener noreferrer">https://api.server.test/v1</a>
37+
</td>
38+
</tr>
39+
</tbody>
40+
</table>
41+
42+
## <span class="api-tag"></span>
43+
44+
<hr class="operation-separator" />
45+
46+
### <span class="http-get">GET</span> /test
47+
48+
49+
<p class="response-title">
50+
<strong>Response <span class="response-code code-200">200</span>&nbsp;<span class="status-phrase">OK</span></strong>
51+
</p>
52+
53+
54+
55+
56+
---

0 commit comments

Comments
 (0)