@lexmin0412/swagger2ts
v0.0.15
Published
a tool for transfer swagger to ts, available both for API and CLI
Downloads
19
Maintainers
Readme
@lexmin0412/swagger2ts
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[]
}
}