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
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
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 );
}
}
var API = require("./api");
var api = new API("http://192.168.86.8:8051");
api.getSkillsUsingGET({}).then(function (response) {
console.log(response.data);
});
Apache-2.0 © jadepeng