|
1 | 1 |  |
2 | 2 | [](https://pypi.python.org/pypi/essentials-openapi) |
3 | 3 | [](https://github.com/neoteroi/essentials-openapi) |
4 | | -[](https://github.com/neoteroi/essentials-openapi/blob/master/LICENSE) |
| 4 | +[](https://github.com/neoteroi/essentials-openapi/blob/main/LICENSE) |
5 | 5 | [](https://codecov.io/gh/Neoteroi/essentials-openapi) |
6 | 6 |
|
7 | 7 | # essentials-openapi |
8 | 8 |
|
9 | | -Classes to generate OpenAPI Documentation v3 and v2, in JSON and YAML. |
| 9 | +Classes to generate [OpenAPI Documentation](https://swagger.io/specification/) |
| 10 | +v3 and v2, in JSON and YAML, and to generate other kinds of documents from |
| 11 | +OpenAPI Documentation files. |
10 | 12 |
|
11 | 13 | ```bash |
12 | 14 | pip install essentials-openapi |
13 | 15 | ``` |
14 | 16 |
|
| 17 | +To install with dependencies to generate other kinds of artifacts from source |
| 18 | +OpenAPI Documentation files: |
| 19 | + |
| 20 | +```bash |
| 21 | +pip install essentials-openapi[full] |
| 22 | +``` |
| 23 | + |
15 | 24 | ## Useful links |
16 | 25 |
|
17 | 26 | * https://swagger.io/specification/ |
18 | 27 | * https://editor.swagger.io |
19 | 28 |
|
20 | 29 | ## Usage |
21 | | -This library has been created to implement generation of OpenAPI Documentation |
| 30 | +This library has been originally created to implement generation of OpenAPI Documentation |
22 | 31 | in the [`BlackSheep` web framework](https://github.com/RobertoPrevato/BlackSheep). |
23 | | -This package contains only parts that belong logically to the OpenAPI specification, |
24 | | -and can be reused for other applications. |
| 32 | +However, this package is abstracted from that web framework and can be reused for other |
| 33 | +applications. Today this library also offers functions to generate documentation from |
| 34 | +source OpenAPI Documentation files. |
| 35 | + |
| 36 | +## Features to generate artifacts from Open API Documentation |
| 37 | + |
| 38 | +These require the full package: install it using `pip install essentials-openapi[full]`. |
| 39 | + |
| 40 | +To generate output for [MkDocs](https://www.mkdocs.org) and [PyMdown extentions](https://facelessuser.github.io/pymdown-extensions/): |
| 41 | + |
| 42 | +```bash |
| 43 | +oad gen-docs -s example1-openapi.json -d output.md |
| 44 | +``` |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +_Example of MkDocs documentation generated using [Neoteroi/mkdocs-plugins](https://github.com/Neoteroi/mkdocs-plugins)._ |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +To generate a [PlantUML](https://plantuml.com) [class |
| 53 | +diagram](https://plantuml.com/class-diagram) of the components schemas: |
| 54 | + |
| 55 | +```bash |
| 56 | +oad gen-docs -s source-openapi.json -d schemas.wsd --style "PLANTUML_SCHEMAS" |
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +_Example of PlantUML diagram generated from components schemas._ |
| 62 | + |
| 63 | +### Goals |
| 64 | + |
| 65 | +* Provide an API to generate OpenAPI Documentation files. |
| 66 | +* Providing functions to handle OpenAPI Documentation, like those to generate |
| 67 | + other kinds of documentation from source OpenAPI Documentation files. |
| 68 | +* Support enough features to be useful for the most common API scenarios, |
| 69 | + especially for OAD files that are generated automatically from web frameworks. |
| 70 | + |
| 71 | +### Non-Goals |
| 72 | + |
| 73 | +* To implement the whole OAD Specification. |
| 74 | +* For the features that generate artifacts: OpenAPI Documentation files are |
| 75 | + **supposed to be coming from trusted sources**. Trying to handle source files |
| 76 | + from untrusted sources and potentially causing HTML injection is out of the |
| 77 | + scope of this library. |
25 | 78 |
|
26 | 79 | ## Limitations |
27 | 80 |
|
28 | | -* Partial support for Parameter properties: `style` , `allow_reserved` , |
29 | | - `explode` are not handled |
30 | | -* Doesn't implement validation of values, currently it is only concerned in |
31 | | - generating code from a higher level API (it might be extended in the future |
32 | | - with classes for validation) |
| 81 | +* Partial support for Parameter properties: `style`, `allow_reserved`, `explode` are not |
| 82 | + handled. |
| 83 | +* Doesn't implement validation of values, currently it is only concerned in generating |
| 84 | + code from a higher level API (it might be extended in the future with classes for |
| 85 | + validation). |
| 86 | +* The features to generate artifacts from OpenAPI Documentation currently support only |
| 87 | + Version 3 of the specification. |
| 88 | + |
| 89 | +### Styles |
| 90 | + |
| 91 | +| Style | Int value | Description | |
| 92 | +| ---------------- | --------- | -------------------------------------------- | |
| 93 | +| MKDOCS | 1 | Markdown for MkDocs and PyMdown extensions. | |
| 94 | +| MARKDOWN | 2 | Basic Markdown. | |
| 95 | +| HTML | 3 | Plain HTML _(planned, not yet implemented)_. | |
| 96 | +| PLANTUML_SCHEMAS | 100 | PlantUML schema for components schemas. | |
| 97 | + |
| 98 | +### Supported sources for OpenAPI Documentation |
| 99 | + |
| 100 | +| Source | Example | |
| 101 | +| ------------------------------ | ---------------------------------------------------- | |
| 102 | +| YAML file | `./docs/swagger.yaml` | |
| 103 | +| JSON file | `./docs/swagger.json` | |
| 104 | +| URL returning YAML on HTTP GET | `https://example-domain.net/swagger/v1/swagger.yaml` | |
| 105 | +| URL returning JSON on HTTP GET | `https://example-domain.net/swagger/v1/swagger.json` | |
0 commit comments