Skip to main content

The Codegen Project - AsyncAPI Extensions

· 3 min read
Jonas Lagoni
The Codegen Project creator

The Codegen Project provides several ways to customize the generated code output through AsyncAPI extensions. In this post, we'll explore the available customization options and how to use them effectively.

Channel naming

The channelName extension property allows you to override the default naming conventions used by the generator. This is particularly useful in several scenarios:

  1. When working with AsyncAPI 2.x documents where channel names are derived from addresses
  2. When you want to enforce specific naming conventions in your codebase
  3. When the auto-generated names don't match your team's preferences
asyncapi: 3.0.0
channels:
user-events:
address: user/signedup/v1
x-the-codegen-project:
# Override the auto-generated channel name
channelName: UserEvents

The channelName property affects several aspects of code generation:

  • Function names (e.g., publishToUserEvents, subscribeToUserEvents)
  • Model class names (e.g., UserEventsPayload, UserEventsParameters)
  • Type definitions and interfaces
  • File names for generated code

This is primarily used for channels and client generators as they generate helper functions, and payload, parameters, and headers model names.

Function type mapping

The functionTypeMapping property allows you to specify which types of protocol functions should be generated for a channel. For example for event source, you have the option to define:

  • event_source_fetch - Generate EventSource client functions using fetch
  • event_source_express - Generate EventSource server functions for express servers

The reason why this extension is needed, especially for channels, is because there is no other way to specify what protocol functions you need. In conjunction with operations, this means that if multiple different types of protocol functions are available, you can selectively decide which ones are relevant.

See the full list here: https://the-codegen-project.org/docs/api/enumerations/ChannelFunctionTypes

Example usage:

asyncapi: 3.0.0
channels:
user-events:
x-the-codegen-project:
functionTypeMapping:
- event_source_fetch

With the corresponding configuration:

export default {
generators: [
{
preset: 'channels',
outputPath: './src/__gen__/',
language: 'typescript',
protocols: ['event_source'],
asyncapiGenerateForOperations: false
}
]
};

It will only generate event source fetch (client) functions for that specific channel.

As mentioned earlier, this can also be defined for operations, the same as for channels. Here specifying event source does not make much sense, but for something like NATS, you can specify whether it's for JetStream or core NATS:

asyncapi: 3.0.0
operations:
publishUserEvent:
x-the-codegen-project:
functionTypeMapping:
- nats_jetstream_publish

With the corresponding configuration:

export default {
generators: [
{
preset: 'channels',
outputPath: './src/__gen__/',
language: 'typescript',
protocols: ['nats']
}
]
};

Future?

There will probably in the future be a unification of these extensions, as all code generations mature and can benefit from these types of extensions.

For now, The Codegen Project's extensions will provide a robust foundation for allowing you to customize the generated code even further. In the future, we will definitely also see more extensions emerge as more use cases get uncovered.

Remember to check the official documentation for the latest updates and additional customization options as they become available.

I will also make sure to update you whenever extensions come to life.

The Codegen Project - 5 Months of Progress

· 5 min read
Jonas Lagoni
The Codegen Project creator

It has been a while since the last update, almost 5 months to be exact, all these improvements have been happening while building the SDK platform, using the CLI as it's pillars.

Since our last update in October 2024, we've evolved the project with new features, expanded protocol support, crucial fixes, and improved documentation. Instead of just listing the changes, we want to share the journey of how we grew The Codegen Project CLI from version 0.23.0 to 0.33.0.

The Codegen Project

· 3 min read
Jonas Lagoni
The Codegen Project creator
Andreas Lagoni
The Codegen Project creator

The Codegen Project banner

The Idea 💡

Apollo GraphQL code generator has always been a pleasure to use, but when it comes to standards such as OpenAPI and AsyncAPI, the same level of code generator or simplicity during the implemenation phase is non-existing.

That is what this project wants to bring;

A bit ambitious perhaps... So how?