https://github.com/jorgermduarte/openapi-interface-generator
A simple TypeScript utility to generate strongly typed contracts based on an OpenAPI YAML specification.
https://github.com/jorgermduarte/openapi-interface-generator
api contracts generator interfaces interfaces-api openapi openapi-generator yaml
Last synced: 4 months ago
JSON representation
A simple TypeScript utility to generate strongly typed contracts based on an OpenAPI YAML specification.
- Host: GitHub
- URL: https://github.com/jorgermduarte/openapi-interface-generator
- Owner: jorgermduarte
- License: mit
- Created: 2025-04-12T23:27:20.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-04-15T13:59:19.000Z (6 months ago)
- Last Synced: 2025-06-10T08:54:49.999Z (4 months ago)
- Topics: api, contracts, generator, interfaces, interfaces-api, openapi, openapi-generator, yaml
- Language: TypeScript
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openapi-interface-generator
A simple TypeScript utility to generate strongly typed contracts (input, output, and interfaces) based on an OpenAPI YAML specification. This tool helps backend and frontend developers work with consistent request and response types.
## Features
- Generate TypeScript interfaces from OpenAPI schemas
- Organize input (request), output (response), and controller interfaces
- Supports nested objects and `$ref` references
- Fully configurable output paths---
## 🛠Installation
```bash
npm install --save-dev openapi-interface-generator
```## 🚀 Usage
### Option 1: Add it to your npm scripts
Add this to your package.json:
```bash
"scripts": {
"generate-interfaces": "openapi-interface-generator --openApiPath=./openapi.yaml --generatedDir=./src/app/contracts --interfacesFolder=interfaces --requestsFolder=requests --responsesFolder=responses"
}
```### Option 2: CLI
```bash
openapi-interface-generator \
--openApiPath=./openapi.yaml \
--generatedDir=./src/app/contracts \
--interfacesFolder=interfaces \
--requestsFolder=requests \
--responsesFolder=responses
```### Running using the npm script
```bash
npm run generate-interfaces
```## âš™ CLI Options
| Option | Description | Default |
|----------------------|----------------------------------------------|--------------------------|
| `--openApiPath` | Path to OpenAPI YAML file | `./openapi.yaml` |
| `--generatedDir` | Base output folder for all contracts | `./src/app/contracts` |
| `--interfacesFolder` | Folder for generated Express interfaces | `interfaces` |
| `--requestsFolder` | Folder for generated request DTOs | `requests` |
| `--responsesFolder` | Folder for generated response DTOs | `responses` |## 📂 Output Structure
```bash
/contracts
├── interfaces
│ └── tag-name-interface.ts <-- Controller interfaces
├── requests
│ └── tag-name.request.ts <-- Input DTOs
└── responses
└── tag-name.response.ts <-- Output DTOs
```