Skip to content

Latest commit

 

History

History
99 lines (65 loc) · 1.72 KB

README.md

File metadata and controls

99 lines (65 loc) · 1.72 KB

swagger-axios-codegen

NpmVersionnpm

require node > v8.0.0

swagger client to use axios and typescript

it will always resolve axios.response.data or reject axios.error with Promise

Get Started

  yarn add swagger-axios-codegen
export interface ISwaggerOptions {
  className: string
  methodNameMode: 'operationId' | 'path'
  type: 'ts' | 'js'  // only implement ts
  outputDir: string
  fileName: string
  useStaticMethod: boolean
}


const defaultOptions = {
  className: 'Service',
  methodNameMode: 'operationId',
  type: 'ts',
  outputDir: './service',
  fileName: 'index.ts'
}

use local swagger api json

const { codegen } = require('swagger-axios-codegen')
codegen({
  methodNameMode: 'operationId',
  source:require('./swagger.json')
})

use remote swagger api json

const { codegen } = require('swagger-axios-codegen')
codegen({
  methodNameMode: 'operationId',
  remoteUrl:'You remote Url'
})

use static method

codegen({
    methodNameMode: 'operationId',
    remoteUrl: 'http://localhost:22742/swagger/v1/swagger.json',
    outputDir: '.',
    useStaticMethod:true
});

before


import { UserService } from './service'
const userService = new UserService()
await userService.GetAll();

after


import { UserService } from './service'

await UserService.GetAll();

Welcome PR and commit issue