Skip to content

NPM package based on swagger-ts-generator to generate typescript models for endpoints documented by swagger using the relatively new OpenAPI spec.

License

Notifications You must be signed in to change notification settings

ikemtz/openapi-ts-generator

Repository files navigation

Build Status npm version npm downloads Quality Gate Status Issues Coverage Lines of Code Security Rating CodeQL

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.

About

NPM package based on swagger-ts-generator to generate typescript models for endpoints documented by swagger using the relatively new OpenAPI spec.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published