@toftcode/swagger-axios-ts-generator
v0.0.8
Published
use swagger api json to auto generate ts code
Downloads
5
Maintainers
Readme
@toftcode/swagger-axios-ts-generator
Install
$ npm install @toftcode/swagger-axios-ts-generator
$ yarn add @toftcode/swagger-axios-ts-generator
Example
TypeScript
import { generate } from '@toftcode/swagger-axios-ts-generator'
generate({
// out files path
out: './testServices',
// service name suffix
serviceNameSuffix: 'Service',
// api json url
url:
'https://raw.githubusercontent.com/toftcode/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('@toftcode/swagger-axios-ts-generator')
generate({
out: './src/testService',
url:
'https://raw.githubusercontent.com/toftcode/swagger-axios-ts-generator/master/test.json',
})