Skip to content

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

Notifications You must be signed in to change notification settings

lexmin0412/swagger2ts

Repository files navigation

@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[]
	}
}

About

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

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published