@toft-code/swagger-axios-ts-generator
v0.2.0
Published
use swagger api json to auto generate ts code
Downloads
2
Maintainers
Readme
@toft-code/swagger-axios-ts-generator
Install
$ npm install @toft-code/swagger-axios-ts-generator
$ yarn add @toft-code/swagger-axios-ts-generator
Example
TypeScript
import { generate } from '@toft-code/swagger-axios-ts-generator'
generate({
// out files path
out: './testServices',
// service name suffix
serviceNameSuffix: 'Service',
// api json url
url:
'https://raw.githubusercontent.com/toft-code/swagger-axios-ts-generator/master/test.json',
// foreach operationId
operationIdForeach: (operationId: string) => {
return operationId.match(/[a-zA-Z]+/g)?.join('') ?? operationId
},
// services/index.ts template
requestTemplateUrl:
'https://raw.githubusercontent.com/toft-tech/swagger-axios-ts-generator/master/src/template/indexAxiosTemplate.ts',
})
CommonJS
const { generate } = require('@toft-code/swagger-axios-ts-generator')
generate({
out: './src/testService',
url:
'https://raw.githubusercontent.com/toft-code/swagger-axios-ts-generator/master/test.json',
})