Documenting¶
Propan allows you not to think about the documentation of your project - it is already generated automatically in accordance with the AsyncAPI specification !
To work with a documentation you should install an extra requirements:
pip install "propan[doc]"
Example¶
Let's look at an example.
To begin with, we will write a small application with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
YAML schema¶
To generate the AsyncAPI specification of your project in the .yaml
format use the following command:
$ propan docs gen example:app
Your project AsyncAPI scheme was placed to `./asyncapi.yaml`
Now you have a scheme of your project: you can use it to generate various clients in any language using an AsyncAPI tools.
Asyncapi.yaml
asyncapi: 2.6.0
defaultContentType: application/json
info:
title: Smartylighting Streetlights Propan API
version: 1.0.0
description: "\n The Smartylighting Streetlights API.\n ### Check out its\
\ awesome features:\n * Turn a specific streetlight on/off \U0001F303\n \
\ * Receive real-time information about environmental \U0001F4C8\n "
servers:
dev:
url: amqp://guest:guest@localhost:5672/
protocol: amqp
protocolVersion: 0.9.1
channels:
HandleLogs:
servers:
- dev
bindings:
amqp:
is: routingKey
bindingVersion: 0.2.0
queue:
name: '*.info'
durable: true
exclusive: false
autoDelete: false
vhost: /
exchange:
name: logs
type: topic
durable: true
autoDelete: false
vhost: /
subscribe:
description: Handle all environmental events
bindings:
amqp:
cc: '*.info'
ack: true
bindingVersion: 0.2.0
message:
$ref: '#/components/messages/HandleLogsMessage'
components:
messages:
HandleLogsMessage:
title: HandleLogsMessage
correlationId:
location: $message.header#/correlation_id
payload:
$ref: '#/components/schemas/HandleLogsPayload'
schemas:
HandleLogsPayload:
title: HandleLogsPayload
type: object
properties:
level:
title: Level
type: integer
message:
title: Message
default: ''
type: string
required:
- level
example:
level: 4015
message: evwWheCeRIGhHEHYxKSJ
Online documentation¶
Also, Propan allows you to host HTML representation of your documentation with the following command
The online representation of documentation does not work without an internet connection, since CDN dependencies are used to display it.
$ propan docs serve example:app
This way you can provide all external consumers with access to your project documentation without additional development costs.
Tip
Propan can also host asyncapi.yaml
files.
propan docs serve asyncapi.yaml
This can be useful if you want to extend the automatically generated AsyncAPI documentation: you just generate a file, modify and host it!
When using online documentation, you can also download it using the following paths:
/asyncapi.json
- JSON schema (available when hosting an application)/asyncapi.yaml
- YAML schema (available for an application and a file both)
FastAPI Plugin¶
When using Propan as a router for FastAPI, the framework automatically registers endpoints for hosting AsyncAPI documentation in your application with the following default values:
1 2 3 4 5 6 |
|
Own hosting¶
For hosting documentation Propan uses FastAPI + uvicorn.
You may want to implement the logic of displaying documentation yourself: restrict access rights, customize content regardless of access rights, embed documentation in your frontend application, and so on.
To do this, you can generate a json
/yaml
/html
document yourself and use it in your own service.
1 2 3 4 5 6 7 8 9 10 11 12 |
|