const {swagger2js} = require('../index');
swagger2js({
swaggerUrl: 'http://your-hostname/v1/api-docs',
pathName: __dirname + '/API'
}, {
useAxios: true,
useLog: true,
saveOriginJson: true
});
import Axios, {
AxiosPromise,
AxiosRequestConfig
} from "axios";
interface Result {
success: boolean;
data: any;
code: number;
message: string;
}
export default {
_baseURL: 'http://your-hostname/pro-name/',
_instance: null,
get getInstance() {
if (!this._instance) {
this._instance = Axios.create({
baseURL: this._baseURL
})
}
return this._instance;
},
set baseURL(url) {
if (this._instance) {
throw new Error('Axios已实例化,无效操作');
}
this._baseURL = url;
},
getQueryParams(query) {
let queryParams = '';
if (query) {
queryParams = Object.keys(query).map(key => `${key}=${query[key]}`).join('&')
}
return queryParams ? '?' + queryParams : '';
},
get_v1_contact_query({
path,
query = {},
body = {},
config = {}
}: {
path ? : {},
query ? : {},
body ? : {},
config ? : AxiosRequestConfig
} | any = {}): AxiosPromise < Result > {
const requestParams = {
url: `v1/contact/query` + this.getQueryParams(query),
method: 'get',
data: body,
...config
};
return this.getInstance.request(requestParams);
},
}