Skip to content

senelway/swagger-to-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


npm

npm i swatts
# or
yarn add swatts

Usage

import swatts from 'swatts';

swatts({
  API: 'http://YOUR-DOMAIN.wtf/swagger/v1/swagger.json',
  regexpMethods: {
    nameInterface?: /(Container|ExtensionTotal)\[(.*)/, // swagger v2
    matchInterfaceName?: /definitions\/(\w+)/, // swagger v2
    excludeDTO: /(RequestDto|ExtensionEmpty)/, 
    replaceSpace: /^\s*[\r\n]/gm,
  },
  modificators: {
    interfaceReplace?: { StatedContainerDto: 'any', 'StatedContainerDto[]': 'any[]' },
    typeReplace: { 'integer': 'number' }
  },
  filePath: __dirname + '/types.ts'
})

Example file

export enum EnumUserRole {
  administrator = 'administrator', // admin
  organizationOwner = 'organizationOwner', // org
}
export interface ProfileDto {
  profileID: number; // ProfileID
  timeZone: string; // TimeZone
  firstName: string; // First name
  lastName: string; // Last name
  email: string; // Email
  userRole: EnumUserRole;
}

About

generate typescript interface and enums using swagger

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published