Skip to content

Commit 9d8a8e0

Browse files
Add new output style for API overviews with PlantUML
1 parent 3090439 commit 9d8a8e0

12 files changed

Lines changed: 176 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ 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.1] - 2022-??-??
9+
- Adds a new output style, to provide an overview of the API endpoints with
10+
PlantUML
11+
812
## [1.0.0] - 2022-04-20 :sparkles:
913
- Adds features and a CLI to generate artifacts from OpenAPI Documentation
1014
files (markdown for MkDocs and PyMdown extensions, PlantUML class diagrams

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ To generate output for [MkDocs](https://www.mkdocs.org) and [PyMdown extentions]
4343
oad gen-docs -s example1-openapi.json -d output.md
4444
```
4545

46-
![Example MkDocs documentation](./docs/example-1.png)
46+
![Example MkDocs documentation](https://gist.githubusercontent.com/RobertoPrevato/38a0598b515a2f7257c614938843b99b/raw/06e157c4f49e27a7e488d72d36d199194e28e952/oad-example-1.png)
4747

4848
_Example of MkDocs documentation generated using [Neoteroi/mkdocs-plugins](https://github.com/Neoteroi/mkdocs-plugins)._
4949

@@ -56,10 +56,23 @@ diagram](https://plantuml.com/class-diagram) of the components schemas:
5656
oad gen-docs -s source-openapi.json -d schemas.wsd --style "PLANTUML_SCHEMAS"
5757
```
5858

59-
![Example schemas](./docs/example-schemas.png)
59+
![Example schemas](https://gist.githubusercontent.com/RobertoPrevato/38a0598b515a2f7257c614938843b99b/raw/06e157c4f49e27a7e488d72d36d199194e28e952/oad-example-schemas.png)
6060

6161
_Example of PlantUML diagram generated from components schemas._
6262

63+
---
64+
65+
To generate a [PlantUML](https://plantuml.com) [class
66+
diagram](https://plantuml.com/class-diagram) with an overview of API endpoints:
67+
68+
```bash
69+
oad gen-docs -s source-openapi.json -d schemas.wsd --style "PLANTUML_API"
70+
```
71+
72+
![Example api overview](https://gist.githubusercontent.com/RobertoPrevato/38a0598b515a2f7257c614938843b99b/raw/3c6fdf85f6dd1a99ba1bd0486707dff557ff4ac4/oad-api-example.png)
73+
74+
_Example of PlantUML diagram generated from path items._
75+
6376
### Goals
6477

6578
* Provide an API to generate OpenAPI Documentation files.
@@ -94,6 +107,7 @@ _Example of PlantUML diagram generated from components schemas._
94107
| MARKDOWN | 2 | Basic Markdown. |
95108
| HTML | 3 | Plain HTML _(planned, not yet implemented)_. |
96109
| PLANTUML_SCHEMAS | 100 | PlantUML schema for components schemas. |
110+
| PLANTUML_API | 101 | PlantUML schema for API endpoints. |
97111

98112
### Supported sources for OpenAPI Documentation
99113

docs/example-1.png

-356 KB
Binary file not shown.

docs/example-schemas.png

-154 KB
Binary file not shown.

openapidocs/mk/jinja.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ class OutputStyle(Enum):
3939
"""Basic Markdown"""
4040

4141
PLANTUML_SCHEMAS = 100
42-
"""PlantUML schema for components schemas."""
42+
"""PlantUML class diagram for components schemas."""
43+
44+
PLANTUML_API = 101
45+
"""PlantUML diagram of the API with request and response bodies."""
4346

4447

4548
class PackageLoadingError(ValueError):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Views to generate PlantUML API schema
2+
3+
This folder contains views to generate a diagram of the API with request
4+
/ response bodies for [PlantUML](https://plantuml.com).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@startuml "API schema"
2+
/'
3+
This diagram has been generated by essentials-openapi
4+
https://github.com/Neoteroi/essentials-openapi
5+
6+
Most likely, it is not desirable to edit this file by hand!
7+
'/
8+
top to bottom direction
9+
hide empty members
10+
11+
{% for tag, operations in handler.get_operations().items() %}
12+
13+
interface "{{tag}} API" as {{tag | lower}}_api {
14+
{%- for path, definition in operations %}
15+
{%- for http_method, operation in definition.items() %}
16+
+ **{{http_method.upper()}}** {{path}}
17+
{%- endfor %}
18+
{%- endfor %}
19+
}
20+
{% endfor %}
21+
22+
@enduml
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{%- if is_reference(schema) -%}
2+
{%- with type_name = schema["$ref"].replace("#/components/schemas/", "") -%}
3+
{{type_name}}
4+
{%- endwith -%}
5+
{%- endif -%}
6+
7+
{%- if schema.type -%}
8+
{%- with type_name = schema["type"], nullable = schema.get("nullable") -%}
9+
{# Scalar types #}
10+
{%- if type_name in scalar_types -%}
11+
{{type_name}}
12+
{%- if schema.format -%}
13+
({{schema.format}})
14+
{%- endif -%}
15+
{%- if nullable %} | null{%- endif -%}
16+
{%- endif -%}
17+
{%- if type_name == "array" -%}
18+
{%- with schema = schema["items"] -%}
19+
Array of {% include "partial/schema-repr.html" -%}
20+
{%- endwith -%}
21+
{%- endif -%}
22+
{%- if type_name == "null" -%}
23+
null
24+
{%- endif -%}
25+
{%- endwith -%}
26+
{%- endif -%}

openapidocs/mk/v3/views_plantuml_schemas/layout.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Most likely, it is not desirable to edit this file by hand!
77
'/
88
top to bottom direction
9+
hide empty members
910

1011
{% for name, definition in handler.get_schemas() %}
1112
class {{name}} {

tests/res/example1-api-output.wsd

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
@startuml "API schema"
2+
/'
3+
This diagram has been generated by essentials-openapi
4+
https://github.com/Neoteroi/essentials-openapi
5+
6+
Most likely, it is not desirable to edit this file by hand!
7+
'/
8+
top to bottom direction
9+
hide empty members
10+
11+
12+
13+
interface "Blobs API" as blobs_api {
14+
+ **POST** /api/blobs/initialize-upload
15+
}
16+
17+
18+
interface "Categories API" as categories_api {
19+
+ **GET** /api/categories
20+
}
21+
22+
23+
interface "Countries API" as countries_api {
24+
+ **GET** /api/countries
25+
+ **GET** /api/system-countries
26+
}
27+
28+
29+
interface "Downloads API" as downloads_api {
30+
+ **GET** /api/downloads
31+
}
32+
33+
34+
interface "Health API" as health_api {
35+
+ **GET** /api/health
36+
}
37+
38+
39+
interface "Professionals API" as professionals_api {
40+
+ **GET** /api/pro/own-context
41+
}
42+
43+
44+
interface "Info API" as info_api {
45+
+ **GET** /api/info
46+
}
47+
48+
49+
interface "Releases API" as releases_api {
50+
+ **GET** /api/releases/{releaseId}
51+
+ **DELETE** /api/releases/{releaseId}
52+
+ **PATCH** /api/releases/{releaseId}
53+
+ **GET** /api/releases
54+
+ **POST** /api/releases
55+
+ **GET** /api/current-releases
56+
+ **GET** /api/orgs/current-releases
57+
+ **GET** /api/releases/{releaseId}/history
58+
+ **GET** /api/releases/{releaseId}/file/{nodeId}
59+
+ **GET** /api/releases/{releaseId}/file/{nodeId}/downloads
60+
+ **PUT** /api/releases/{releaseId}/files
61+
+ **DELETE** /api/releases/{releaseId}/files
62+
+ **PUT** /api/releases/{releaseId}/orgs
63+
+ **DELETE** /api/releases/{releaseId}/orgs
64+
+ **POST** /api/releases/{releaseId}/clone
65+
+ **POST** /api/releases/{releaseId}/publish
66+
}
67+
68+
69+
@enduml

0 commit comments

Comments
 (0)