openapi-typescript-generator
v1.3.4
Published
Swagger typescript interface and api generator.
Downloads
21
Readme
OpenAPI TypeScript Generator
An awesome Swagger OpenAPI schema to TypeScript Interface and API generator.
Installation
To install the package run:
npm install --save-dev openapi-typescript-generator
Usage
To use the package run:
otsgen <swagger-url>
Configuration
Create a configuration file called otsgen.config.js
. Default configuration file looks as follows:
const path = require('path');
module.exports = {
templates: {
model: path.resolve(__dirname, 'templates', 'model.ejs'),
index: path.resolve(__dirname, 'templates', 'index.ejs'),
service: path.resolve(__dirname, 'templates', 'service.ejs'),
api: path.resolve(__dirname, 'templates', 'api.ejs'),
apiConfig: path.resolve(__dirname, 'templates', 'api.config.ejs')
},
model: {
output(input) {
const object = input.replace('#/components/schemas/', '');
const name = `I${object}`;
const path = `I${object}.ts`;
return { name, path };
}
},
service: {
output(input) {
const name = input.replace('Controller', 'Service');
const path = name.split(/(?=[A-Z])/)
.map(x => x.toLowerCase())
.join('-')
.replace('-service', '.service.ts');
return { name, path };
}
},
output: {
models: path.resolve(outputDir, 'models'),
services: path.resolve(outputDir, 'services')
},
api: {
variables: {
API_URL: 'API_URL',
API_CONFIG: 'API_CONFIG',
AXIOS_CONFIG: 'AXIOS_CONFIG'
}
},
axios: {}
}
CLI Arguments
Output --output
-o
otsgen <swagger-url> --output dist
Config --config
-c
otsgen <swagger-url> --config otsgen.config.js