1.3.4 • Published 3 years ago
openapi-typescript-generator v1.3.4
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
1.3.4
3 years ago
1.3.3
3 years ago
1.3.2
3 years ago
1.3.1
3 years ago
1.3.0
3 years ago
1.2.9
4 years ago
1.2.8
4 years ago
1.2.7
4 years ago
1.2.6
4 years ago
1.2.5
4 years ago
1.2.4
4 years ago
1.2.3
4 years ago
1.2.2
4 years ago
1.2.1
4 years ago
1.2.0
4 years ago
1.1.0
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.3
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago