npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@odit/swagger-axios-codegen

v1.0.0

Published

A swagger client using axios and typescript

Downloads

81

Readme

@odit/swagger-axios-codegen

A swagger client using axios and typescript

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

Get Started

pnpm i -D @odit/swagger-axios-codegen

export interface ISwaggerOptions {
  /** service name suffix eg. 'Service' **/
  serviceNameSuffix?: string
  /** enum prefix eg. 'Enum' **/
  enumNamePrefix?: string
  methodNameMode?: 'operationId' | 'path'
  /** path of the generated file eg. './src/service' **/
  outputDir?: string
  /** generated file name eg. 'index.ts' **/
  fileName?: string
  /** path to remote source file eg. 'https://localhost:8080/api/v1/swagger.json' **/
  remoteUrl?: string
  /** path to local source file eg. './swagger.json' **/
  source?: any
  useStaticMethod?: boolean | undefined
  /** client can pass custom headers to the service methods **/
  useCustomerRequestInstance?: boolean | undefined
  /** filter by service name (first tag) or method name using multimatch (https://github.com/sindresorhus/multimatch) **/
  include?: Array<string | IInclude>
  /** include extra types which are not included during the filtering Eg. ["Foo", "Bar"] **/
  includeTypes?: Array<string>
  /** filter urls by following clauses **/
  urlFilters?: Array<string>
  /** custom function to format the output file (default: prettier.format()) **/
  format?: (s: string) => string
  /** match with tsconfig */
  strictNullChecks?: boolean | undefined
  /** definition Class mode */
  modelMode?: 'class' | 'interface'
  /** use class-transformer to transform the results */
  useClassTransformer?: boolean,
  // force the specified swagger or openAPI version,
  openApi?: string | undefined,
  // extend file url. It will be inserted in front of the service method
  extendDefinitionFile?: string | undefined
  // mark generic type
  extendGenericType?: string[] | undefined
  /** split request service.  Can't use with sharedServiceOptions*/
  multipleFileMode?: boolean | undefined
  /** shared service options to multiple service. Can't use with MultipleFileMode */
  sharedServiceOptions?: boolean | undefined
}

const defaultOptions: ISwaggerOptions = {
  serviceNameSuffix: 'Service',
  enumNamePrefix: 'Enum',
  methodNameMode: 'operationId',
  outputDir: './service',
  fileName: 'index.ts',
  useStaticMethod: true,
  useCustomerRequestInstance: false,
  include: [],
  strictNullChecks: true,
  /** definition Class mode ,auto use interface mode to streamlined code*/
  modelMode?: 'interface',
  useClassTransformer: false
}

use local swagger api json


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

use remote swagger api json


const { codegen } = require('@odit/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

import axios from 'axios'
import { serviceOptions } from './service'
const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});

serviceOptions.axios = instance