Skip to content

wangxb07/hotpot-swagger-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hotpot-swagger-client

Simple swagger client by typescript

Usage

The manager instance initialization

const swagger = new Swagger({
  spec: {...},
});

Swagger can build the client instance by swagger 'tags' defined in spec.

const client = swagger.get('order')

const params = {
  body: {
    ...
  },
  query: {
    ...
  }
};

const res = await client.exec('getOrder', params)

// or 

const res = await client.getOrder(params)

Swagger custom fetch

interface FetchableInterface {
  fetch(url, options): Promise<any>;
}

class myHttpClient implements FetchableInterface {
  fetch(url, options): Promise<any> {
    throw new Error()
  }
}

const swagger = new Swagger({
  spec: {...},
  httpClient: myHttpClient
});

Model mapping

swagger.mappings({
  'order': [
    {from: 'addressLine', to: 'address'},
    {from: 'addressLine', to: 'address', process: (address) => {
      return address[0] + address[1]
    }},
  ]
})

About

Simple swagger client by typescript

Resources

License

Stars

Watchers

Forks

Packages

No packages published