openapi-ts-generator
v7.339.6
Published
Based on swagger-ts-generator, this is a type script model generator specifically for services with OpenApi spec documentation.
Downloads
311
Maintainers
Readme
OpenApi-TS-Generator
NPM package based on swagger-ts-generator to generate typescript models for endpoints documented by swagger using the relatively new OpenAPI spec.
TypeScript usage with a hosted OpenApi Spec document.
import { generateTsModels } from 'openapi-ts-generator';
generateTsModels({
openApiJsonUrl: '{Your Swagger Enpoint URL here}',
outputPath: './{outputFolder}/',
});
TypeScript usage with an OpenApi Spec document stored on your local computer.
import { generateTsModels } from 'openapi-ts-generator';
generateTsModels({
openApiJsonFileName: '{location and file name of your OpenApi document}',
outputPath: './{outputFolder}/',
});
Javascript usage with a hosted OpenApi Spec document.
const generator = require('openapi-ts-generator');
generator.generateTsModels({
openApiJsonUrl: '{Your Swagger Enpoint URL here}',
outputPath: './{outputFolder}/',
genAngularFormGroups: true /* Set this to true if only if you're in an Angular project*/
});
Javascript usage with an OpenApi Spec document stored on your local computer.
const generator = require('openapi-ts-generator');
generator.generateTsModels({
openApiJsonFileName: '{location and file name of your OpenApi document}',
outputPath: './{outputFolder}/',
});
Want to include Angular FormGroup Factories?
const generator = require('openapi-ts-generator');
generator.generateTsModels({
openApiJsonFileName: '{location and file name of your OpenApi document}',
outputPath: './{outputFolder}/',
genAngularFormGroups: true
});
Working example with NRSRx based service
import { generateTsModels } from 'openapi-ts-generator';
generateTsModels({
openApiJsonUrl: 'https://im-wa-cmpo-nrsr.azurewebsites.net/swagger/v1/swagger.json',
outputPath: './models/',
typeFilterCallBack: (val, i, arr) => !val.name.endsWith('ODataEnvelope'),
valuePropertyTypeFilterCallBack: (val, i, arr) => !val.name.startsWith('created') && !val.name.startsWith('updated'),
});
Check out openapi-mermaid, it will auto-generate mermaid entity diagrams using your swagger docs.