Skip to content

hql7/generator-swagger-2-ts

 
 

Repository files navigation

generator-swagger-2-ts NPM version Build Status Dependency Status

A Swagger Codegen for typescript and javascript, A Yeoman generator

This package generates a js/typescript class from a swagger url. The code is generated using Yeoman and you can modify template to diy the generated code

中文文档

Installation

First, install Yeoman and generator-swagger-2-ts using npm (we assume you have pre-installed node.js).

npm install -g yo
npm install -g generator-swagger-2-ts

Then generate your new project:

yo swagger-2-ts

According to the prompt:

  • input swagger - UI address, for example: http://192.168.86.8:8051/swagger-ui.html, the package will automatically replace the url address 'swagger-ui.html' to 'v2/api-docs' to get really swagger API docs url, then download and parse it to generate the API class
  • choose generate js or typescript
  • you can customize the generated API class name, API file name

generated CODE:

export default class API {
    $defaultDomain = 'http://localhost:8051'
    /**
    * @method
    * @name API#getSkillsUsingGET
    * @param string authorization  
    * @param $domain 
    */
    getSkillsUsingGET (parameters){ 
      let body = null;
      let config = {
        baseURL: parameters.$domain || this.$defaultDomain,
        url: '/api/skill',
        method: 'GET'
      };
      config.headers = {}
      config.headers['Accept'] = '*/*';
      config.headers['authorization'] = parameters.authorization;
      config.data = body
      return axios.request( config );
    }
}

Use the API Class

var API = require("./api");
var api = new API("http://192.168.86.8:8051");
api.getSkillsUsingGET({}).then(function (response) {
    console.log(response.data);
});

Reference

License

Apache-2.0 © jadepeng

About

A Swagger Codegen for typescript and javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 75.2%
  • HTML 24.8%