Generate payload models, parameters, headers, messages, communication support functions, and much more...
Read the Docs | View Demos
- 📃 From your AsyncAPI v2 and v3 documents, generate payloads, headers, parameters, protocol helpers, full clients, models, simple types, or all of the above.
- 📃 From your Swagger 2.0, or OpenAPI 3.0, and 3.1 documents, generate payloads, headers, parameters, models, simple types, or all of the above.
- 📃 From your JSON Schema Draft-4, Draft-6 and Draft-7 schemas, generate models or completely customize it.
- 📊 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...
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 generators 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
CodeForge
Automated SDK generation platform built on The Codegen Project
|
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.
Installing the CLI can be done inside a project or within your system.
Package manager
MacOS x64
MacOS arm64
Windows x64
Windows x32
Linux (Debian)
Linux (Others)
npm install --save-dev @the-codegen-project/cli
npm install -g @the-codegen-project/cli
yarn add @the-codegen-project/cli
pnpm add @the-codegen-project/cli
bun add @the-codegen-project/cli
|
curl -OL https://github.com/the-codegen-project/cli/releases/latest/download/codegen.x64.pkg
sudo installer -pkg codegen.x64.pkg -target /
|
curl -OL https://github.com/the-codegen-project/cli/releases/latest/download/codegen.arm64.pkg
sudo installer -pkg codegen.arm64.pkg -target /
|
|
|
curl -OL https://github.com/the-codegen-project/cli/releases/latest/download/codegen.deb
sudo apt install ./codegen.deb
|
curl -OL https://github.com/the-codegen-project/cli/releases/latest/download/codegen.tar.gz
tar -xzf codegen.tar.gz
ln -s <absolute-path>/bin/codegen /usr/local/bin/codegen
|
You can find all the possible commands in the usage documentation.
Add a configuration file, either manually or through the CLI;
codegen init
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.
# Generate code once
codegen generate
# Generate with specific config file
codegen generate ./my-config.js
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.
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
- 📃 3 Published resources (blog post, video, etc)
People who have been so kind to write or talk about The Codegen Project;
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 disable
Or set an environment variable:
export CODEGEN_TELEMETRY_DISABLED=1
# or
export DO_NOT_TRACK=1
Learn more about telemetry →
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.
Thanks go out to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind are welcome!