AsyncAPI tooling update - Week 33

Jonas Lagoni Avatar

Jonas Lagoni

ยท4 min read

This post bundles updates from the following official tools, but not limited to: bundler, chatbot, studio, diff, glee, create-glee-app, cli, optimizer, modelina, generator, generator-react-sdk, java-template, java-spring-cloud-stream-template, java-spring-template, dotnet-nats-template and ts-nats-template.

You can find the last tooling update here.

Highlights

These are some of the highlights of changes that have happened in the tools and what's to come! Let me know what you wish to see from these updates, as I did not end up adding all the individual commits as I did in the last update but choose to only highlight certain features here now and to come. It of course does not cover all the changes, so I am trying to find a balance somewhere.

Modelina

As Modelina creeps closer and closer to version 1, we need to start to think about its vision and goals. Therefore I have started a discussion with the proposed vision and goals. The proposed vision is that Modelina becomes the GOTO solution for generating models for APIs - but, how do we achieve that?

Proposed Goals

  • 250 contributors and at least two champions, per area of responsibility ๐Ÿค
  • At least three ways to serialize models 3๏ธโƒฃ
  • Regardless of your input, Modelina supports it ๐Ÿ’ฏ

If you want to influence the future of Modelina, jump into the discussion!

Rust

As aired in the last update a Rust generator was in the works, and it finally arrived thanks to leigh-johnson!

1import { RustGenerator } from '@asyncapi/modelina';
2const input = {
3  asyncapi: '2.4.0',
4  info: {
5    title: 'example',
6    version: '0.1.0'
7  },
8  channels: {
9    'user/signedup': {
10      subscribe: {
11        message: {
12          payload: {
13            $schema: 'http://json-schema.org/draft-07/schema#',
14            $id: 'root',
15            type: 'object',
16            additionalProperties: false,
17            properties: {
18              email: {
19                type: 'string',
20                format: 'email'
21              }
22            }
23          }
24        }
25      }
26    }
27  }
28};
29const generator = new RustGenerator();
30const models = await generator.generate(input);
31...

A simple Rust usage example with Modelina.

1#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
2pub struct Root {
3  #[serde(rename="email", skip_serializing_if = "Option::is_none")]
4  email: Option<String>,
5}
6impl Root {
7  pub fn new(email: Option<String>) -> Root {
8    Root {
9      email,
10    }
11  }
12}

A simple Rust struct generated for the message payload

The Rust generator contains many features, such as generating tuples types, unions, enums, structs, and even the crate file!

You can read more about the feature here.

Python

Python is right around the corner, which builds on what Mahak started within the next branch. It will start off with only the core models, without any presets to add JSON Serializers, etc, but it's a good start!

Bundler

If you love decoupling your AsyncAPI documents, you might have reasons to bundle them all together within a single AsyncAPI document at some point. This is what the bundler can help you with, and a feature that is brewing that enables you to bundle external resources into the components section of the AsyncAPI document.

1asyncapi: '2.4.0'
2info:
3  title: Account Service
4  version: 1.0.0
5  description: This service is in charge of processing user signups
6channels:
7  user/signup:
8    subscribe:
9      message:
10        $ref: './UserSignedUp.yaml'

The scattered AsyncAPI document (asyncapi.yaml)

And with an external message definition for the UserSignedUp.

1payload:
2  type: object
3  properties:
4    displayName:
5      type: string
6      description: Name of the user
7    email:
8      type: string
9      format: email
10      description: Email of the user

The separated message definition (UserSignedUp.yaml)

The bundler can then place all the external dependencies into the components sections to give you the bundled AsyncAPI document:

1asyncapi: 2.4.0
2info:
3  title: Account Service
4  version: 1.0.0
5  description: This service is in charge of processing user signups
6channels:
7  user/signedup:
8    subscribe:
9      message:
10        $ref: '#/components/messages/UserSignedUp'
11components: 
12  messages:
13    UserSignedUp:
14      payload:
15        type: object
16        properties:
17          displayName:
18            type: string
19            description: Name of the user
20          email:
21            type: string
22            format: email
23            description: Email of the user

The bundled AsyncAPI document that uses local references (asyncapi.bundled.yaml)

To that end

In the end, thank you to everyone who contributes to AsyncAPI in any way you can ๐Ÿ’œ If you also want to help out but don't know where to begin, then join the #11_how-to-contribute channel on Slack so we can help you any way we can ๐Ÿ’ช

If you have worked on something or are working on something that you would like to be included in these updates, feel free to reach out on slack!

Photo by Markus Winkler on Unsplash