@lexmin0412/swagger2ts
TypeScript icon, indicating that this package has built-in type declarations

0.0.15 • Public • Published

@lexmin0412/swagger2ts

NPM version NPM downloads

A tool for transfer swagger to ts, available both for API and CLI.

Install

# install in current project, better for API usage
npm install @lexmin0412/swagger2ts
# install global, better for CLI usage
npm install @lexmin0412/swagger2ts -g

Usage

API Usage

import path from 'path'
import { gen } from '@lexmin0412/swagger2ts'

const rootDir = path.resolve(__dirname)
const requestInstancePath = path.resolve(__dirname, 'src', 'request.ts')

gen({
  rootDir,
  requestInstancePath,
  excludeDirs: [
    'assets',
  ],
  transformConfig: {
    var2TypeMap: {
      'string': [
        'id',
        "parent_id"
      ],
      'string[]': [
        'ids'
      ]
    },
  }
})

CLI Usage

npx s2c ./

Options

interface GenOptions {
	/**
	 * root dir for excuting tasks to generate files
	 */
	rootDir: string
	/**
	 * path for your custom request instance
	 */
	requestInstancePath: string
	/**
	 * excluded paths when scanning *.swagger.json files
	 */
	excludeDirs: string[]
	/**
	 * type transforming configuration
	 */
	transformConfig: {
		/**
		 * variable type transforming map
		 */
		var2TypeMap: {
			[key: string]: string[]
		}
		/**
		 * variable list that should be transformed to string
		 */
		toStringVars?: string[]
	}
}

Package Sidebar

Install

npm i @lexmin0412/swagger2ts

Weekly Downloads

15

Version

0.0.15

License

ISC

Unpacked Size

17.1 kB

Total Files

6

Last publish

Collaborators

  • cellerchan