Customizing AsyncAPI Documentation for FastStream#
In this guide, we will explore how to customize AsyncAPI documentation for your FastStream application. Whether you want to add custom app info, broker information, handlers, or fine-tune payload details, we'll walk you through each step.
Prerequisites#
Before we dive into customization, ensure you have a basic FastStream application up and running. If you haven't done that yet, let's setup a simple application right now.
Copy the following code in your basic.py file:
Now, when you run
you should see the following documentation:Setup Custom FastStream App Info#
Let's start by customizing the app information that appears in your AsyncAPI documentation. This is a great way to give your documentation a personal touch. Here's how:
- Locate the app configuration in your FastStream application.
- Update the
title
,version
, anddescription
fields to reflect your application's details. - Save the changes.
- Serve your FastStream app documentation.
Copy the following code in your basic.py file, we have highlighted the additional info passed to FastStream app:
Now, when you run
you should see the following in your general app documentation:Now, your documentation reflects your application's identity and purpose.
Note
The description
field in the above example supports Markdown
text.
Setup Custom Broker Information#
The next step is to customize broker information. This helps users understand the messaging system your application uses. Follow these steps:
- Locate the broker configuration in your FastStream application.
- Update the
description
field. - Update the
asyncapi_url
field with a non-sensitive URL if you want to conceal your broker's actual bootstrap server URL. - Save the changes.
- Serve your FastStream app.
Copy the following code in your basic.py file, we have highlighted the additional info passed to the FastStream app broker:
Now, when you run
you should see the description in your broker documentation:Your AsyncAPI documentation now provides clear insights into the messaging infrastructure you're using.
Setup Custom Handler Information#
Customizing handler information helps users comprehend the purpose and behavior of each message handler. Here's how to do it:
- Navigate to your handler definitions in your FastStream application.
- Add descriptions to each handler using
description
field. - For subscriber, consumer function's docstring can be used as
description
. - Add titles to each handler using
title
field adhering to URI format. - Add publishing schema to publisher handler using
schema
field. - Save the changes.
- Serve your FastStream app.
Copy the following code in your basic.py file, we have highlighted the additional info passed to the FastStream app handlers:
Now, when you run
you should see the descriptions in your handlers:Now, your documentation is enriched with meaningful details about each message handler.
Setup Payload Information via Pydantic Model#
To describe your message payload effectively, you can use Pydantic models. Here's how:
- Define Pydantic models for your message payloads.
- Annotate these models with descriptions and examples.
- Use these models as argument types or return types in your handlers.
- Save the changes.
- Serve your FastStream app.
Copy the following code in your basic.py file, we have highlighted the creation of payload info and you can see it being passed to the return type and the msg
argument type in the on_input_data
function:
Now, when you run
you should see the payload schema described in your documentation:Your AsyncAPI documentation now showcases well-structured payload information.
Generate Schema.json, customize and serve it#
To take customization to the next level, you can manually modify the schema.json file. Follow these steps:
- Generate the initial schema.json by running
- Manually edit the
asyncapi.json
file to add custom fields, descriptions, and details. - Save your changes.
- Serve your FastStream app with the updated asyncapi.json by running
Now, you have fine-tuned control over your AsyncAPI documentation.
Conclusion#
Customizing AsyncAPI documentation for your FastStream application not only enhances its appearance but also provides valuable insights to users. With these steps, you can create documentation that's not only informative but also uniquely yours.
Happy coding with your customized FastStream AsyncAPI documentation!