New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

swagger-axios-codegen-es6

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-axios-codegen-es6

A swagger client uses axios and es6

0.5.9
latest
Source
npm
Version published
Weekly downloads
4
Maintainers
1
Weekly downloads
 
Created
Source

swagger-axios-codegen-es6

A swagger client uses axios and es6

NpmVersionnpm Build Status open issues

require node > v8.0.0

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

support other similar to axios library, for example Fly.js, required setting ISwaggerOptions.useCustomerRequestInstance = true

Example

ChangeLog

Get Started

  yarn add swagger-axios-codegen

export interface ISwaggerOptions {
  serviceNameSuffix?: string
  enumNamePrefix?: string
  methodNameMode?: 'operationId' | 'path'
  outputDir?: string
  fileName?: string
  remoteUrl?: string
  source?: any
  useStaticMethod?: boolean | undefined
  useCustomerRequestInstance?: boolean | undefined
  include?: Array<string | IInclude>
  format?: (s: string) => string
}

const defaultOptions: ISwaggerOptions = {
  serviceNameSuffix: 'Service',
  enumNamePrefix: 'Enum',
  methodNameMode: 'operationId',
  outputDir: './service',
  fileName: 'index.ts',
  useStaticMethod: true,
  useCustomerRequestInstance: false,
  include: []
}

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();

use custom axios.instance

Create a service/index.js than export your generated service file with custom axios instance

//services/index.js
import axios from 'axios'
import { ProductService } from './generated/Product'

const getAxiosInstance = serviceKey => {
  return axios.create({
    baseURL: process.env[`API_END_POINT_${serviceKey}`],
    timeout: 1000,
    headers: { 'X-Custom-Header': 'foobar' },
  });
};

ProductService.axios = getAxiosInstance('PRODUCT');

export { ProductService };


use other library

import YourLib from '<Your lib>'
import { serviceOptions } from './service'

serviceOptions.axios = YourLib

filter service and method


let include = [
  'Products', // tagName
  'Estimates',//tagName
  { 'User': ['history'] }
]
codegen({
  methodNameMode: 'path',
  source: require('../swagger.json'),
  outputDir: './swagger/services',
  include
})

Welcome PRs and commit issue

⭐⭐⭐⭐⭐

Keywords

swagger

FAQs

Package last updated on 29 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts