A robust API development toolkit powered by TypeSpec, enabling seamless API design and generation.
ez-api leverages Microsoft's TypeSpec to define and maintain consistent APIs across projects. This toolkit streamlines the API development workflow with powerful developer experience (DX) features.
- TypeSpec Integration: First-class support for Microsoft's TypeSpec specification language
- Project Generation: Quick scaffolding with predefined archetypes
- Import OpenAPI Specs: Import existing OpenAPI specifications into TypeSpec projects
- OpenAPI Compliance: Automatic generation of OpenAPI 3.0 specifications
- Developer Tools: Enhanced DX with built-in utilities
- Node.js (v20 or higher)
- TypeSpec CLI (
npm install -g @typespec/compiler) - Visual Studio Code as editor
- Official TypeSpec VSCode extension
- Prettier extension for VSCode (optional)
npm install- Create your first API project:
npm run api:new my-awesome-apior import an existing OpenAPI specification:
npm run api:import my-awesome-api path/to/openapi.yaml- Customize project settings in
config.json:
{
"filename": "api-my-awesome-api",
"version": "1.0.0-beta.1"
}- Build OpenAPI specifications:
npm run compile:my-awesome-apiapi-importto import existing OpenAPI specifications into a new TypeSpec projectapi-newto creates a new API project using predefined archetypespostbuildto generates OpenAPI specification files in both YAML and JSON formats
ez-api/
├── dist/
│ └── my-awesome-api/
│ ├── api-1.0.0-beta.1.yaml # OpenAPI spec (YAML)
│ └── api-1.0.0-beta.1.json # OpenAPI spec (JSON)
├── doc/
│ └── my-awesome-api/
│ ├── api-x.y.z.yaml # Development version (YAML)
│ └── api-x.y.z.json # Development version (JSON)
├── ext/
│ └── <ext-name>.tsp # TypeSpec extension file
├── projects/
│ └── my-awesome-api/
│ ├── model/ # Model definitions
│ ├── routes/ # API routes
│ ├── config.json # Project configuration
│ ├── main.tsp # Main TypeSpec file
│ ├── tspconfig-json.yaml # TypeSpec configuration for JSON
│ └── tspconfig-yaml.yaml # TypeSpec configuration for YAML
├── tools/
│ ├── api-import.ts # Custom project generator for importing OpenAPI specs
│ ├── api-new.ts # Custom project generator according archetype
│ └── postbuild.ts # Custom build script
└── package.json- Define your API using TypeSpec in the
projects/<YOUR_PROJECT>directory - Use built-in TypeSpec decorators for API customization
- Run the
compile:<YOUR_PROJECT>command to generate OpenAPI specifications - Validate generated specifications with your preferred OpenAPI tools
- Keep models and operations in separate directories
- Use TypeSpec's built-in validation features
- Maintain consistent naming conventions
- Document your APIs thoroughly using TypeSpec comments
After running the compile:<YOUR_PROJECT> command, you'll find:
api-<YOUR_PROJECT>-<VERSION>.yaml: OpenAPI 3.0 specification in YAML formatapi-<YOUR_PROJECT>-<VERSION>.json: OpenAPI 3.0 specification in JSON format
These files are fully compatible with any OpenAPI tooling and can be used for:
- API documentation
- API testing