@the-codegen-project/cli
v0.62.1
Published
CLI to work with code generation in any environment
Readme
Core Features
- 📃 Generate payloads, headers, parameters, protocol helpers, full clients, models, simple types, or all of the above from your AsyncAPI v2 and v3
- 📃 Generate payloads, headers, parameters, models, simple types, or all of the above from your Swagger 2.0, or OpenAPI 3.0, and 3.1
- 📃 Generate models or completely customize it for JSON Schema Draft-4, Draft-6 and Draft-7
- 📊 Every generator fully customizable to fit your hearts desire
- 👀 Integrate it into any project (Demos in Next.JS, TypeScript Libraries)
- 💅 Create custom generators to your use-case
- 🗄️ Protocol agnostic generator (NATS, Kafka, MQTT, AMQP, event-source, HTTP Client, WebSocket, read the docs for the full list and information)
- ⭐ And much more...
How it works
The Codegen Project is a generator that is built to live alongside your projects to help you save time in the development phase, ensuring you spend as much time on the business logic as possible. It works by using your configuration file to know what it needs to generate.
Each input has different generates and all of them can be customized, or you can build your own generator right in the configuration file.
export default {
inputType: 'asyncapi',
inputPath: './asyncapi.json',
language: 'typescript',
generators: [
{
preset: 'payloads',
outputPath: './src/payloads',
serializationType: 'json',
},
...
]
};In this example, the generator will read the AsyncAPI document located in same directory as the configuration file, and generate TypeScript models for all the payload including code to serialize the models to JSON.
💎 Sponsors
Getting started
Its simple, install the CLI into your project or machine, setup the Codegen configuration file to include all the code your heart desire, customize it, and generate it at build time or whenever you feel like it.
Install
Installing the CLI can be done inside a project or within your system.
NPM
npm install --save-dev @the-codegen-project/cli
npm install -g @the-codegen-project/cliYarn
yarn add @the-codegen-project/cliPnpm
pnpm add @the-codegen-project/cliBun
bun add @the-codegen-project/cliDownload
curl -OL https://github.com/the-codegen-project/cli/releases/latest/download/codegen.x64.pkgInstall
sudo installer -pkg codegen.x64.pkg -target /Download
curl -OL https://github.com/the-codegen-project/cli/releases/latest/download/codegen.arm64.pkgInstall
sudo installer -pkg codegen.arm64.pkg -target /Download
curl -OL https://github.com/the-codegen-project/cli/releases/latest/download/codegen.debInstall
sudo apt install ./codegen.debDownload
curl -OL https://github.com/the-codegen-project/cli/releases/latest/download/codegen.tar.gzInstall
tar -xzf codegen.tar.gzSymlink
ln -s <absolute-path>/bin/codegen /usr/local/bin/codegenYou can find all the possible commands in the usage documentation.
Initialize
Add a configuration file, either manually or through the CLI;
codegen initCustomize it to your heart's desire!
Generate
With your configuration file in hand, time to generate the code and use it! This can be done manually or integrate into your build process. Checkout all the examples for inspiration on how to do it.
Basic Generation
# Generate code once
codegen generate
# Generate with specific config file
codegen generate ./my-config.jsWatch Mode (Development)
For development workflows, use watch mode to automatically regenerate code when your input files change:
# Watch for changes in the input file specified in your config
codegen generate --watch
# Watch for changes in a specific file or directory
codegen generate --watch --watchPath ./asyncapi
# Short form
codegen generate -w -p ./schemas/Watch mode is perfect for development environments where you want your generated code to stay in sync with your API specifications as you make changes.
👀 Goals
Besides the milestones, we have certain goals that we want to reach for various reasons;
- [ ] ⭐ Reach 50 stars - So we can publish the CLI on Brew and Chocolatey
- [X] 📃 3 Published resources (blog post, video, etc)
📃 Resources
People who have been so kind to write or talk about The Codegen Project;
- AsyncAPI - Simplifying Channels Into One
- AsyncAPI - Protocol-Specific Messaging Functions
- AsyncAPI - Dynamic Channel Routing Made Type-Safe
- AsyncAPI - Type safety Never Publish to Wrong Channels Again
- AsyncAPI - Type-Safe Headers
- AsyncAPI - Stop wasting time on payloads
- The Codegen Project - 1 Months of Progress
- The Codegen Project - AsyncAPI Extensions
- The Codegen Project - 5 Months of Progress
Telemetry
The Codegen Project CLI collects anonymous usage data to help us understand how the tool is being used and make data-driven improvements. We take your privacy seriously:
- ✅ What we collect: Command usage, generator types, input source types (not actual paths), error categories
- ❌ What we DON'T collect: File paths, file contents, personal information, project names
To disable telemetry:
codegen telemetry disableOr set an environment variable:
export CODEGEN_TELEMETRY_DISABLED=1
# or
export DO_NOT_TRACK=1Contribution Guidelines
We have made quite a comprehensive contribution guide to give you a lending hand in how the project is structured and how to contribute to it.
Contributors
Thanks go out to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind are welcome!

