G1 API Generator
A command-line tool for generating TypeScript API clients from OpenAPI schemas.
Features
- Downloads OpenAPI schema from a specified URL
- Generates TypeScript interfaces and API client code
- Post-processes generated code to fix common issues
- Supports HTTPS with option to skip TLS verification
- Detects and warns about duplicate DTOs in the schema
Installation
# Install from G1 package registry
npm install @g1/api-generator --save-dev
# Or with pnpm
pnpm add @g1/api-generator -D
Usage
Command Line
# Basic usage
g1-api-generator https://your-api-server/openapi/schema.json ./src/lib/api
# Skip TLS verification (useful for local development with self-signed certificates)
g1-api-generator https://localhost:7205/openapi/schema.json ./src/lib/api --skip-tls-verify
In package.json scripts
{
"scripts": {
"api:generate": "g1-api-generator https://localhost:7205/openapi/schema.json src/lib/api"
}
}
Programmatic Usage
import { generateApiClient } from '@g1/api-generator';
async function generateApi() {
await generateApiClient({
schemaUrl: 'https://your-api-server/openapi/schema.json',
outputDir: './src/lib/api',
skipTlsVerify: true, // Optional, default: false
runPostProcessing: true // Optional, default: true
});
}
generateApi().catch(console.error);
Generated Code Structure
The generated code is organized as follows:
models/
- TypeScript interfaces for API modelsservices/
- API client services for making requestscore/
- Core functionality for the API clientopen-api.json
- The downloaded and processed OpenAPI schema
Post-Processing
The tool automatically applies the following post-processing to the generated code:
- Removes import statements for
void
type - Replaces usages of
void
as a type withany
- Detects and replaces self-referencing DTOs with
any
- Adds auto-generated comments to files
License
UNLICENSED - Private package for Generation One use only.