mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-07 08:00:50 +00:00
ES6-ify typescript promises, update tests, remove bluebird dependency in favor of ES6 promises
This commit is contained in:
parent
3fba32573c
commit
6c3701a403
@ -1,5 +1,4 @@
|
|||||||
import request = require('request');
|
import request = require('request');
|
||||||
import promise = require('bluebird');
|
|
||||||
import http = require('http');
|
import http = require('http');
|
||||||
|
|
||||||
let defaultBasePath = '{{basePath}}';
|
let defaultBasePath = '{{basePath}}';
|
||||||
@ -24,7 +23,7 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
|
|||||||
* {{{description}}}
|
* {{{description}}}
|
||||||
*/
|
*/
|
||||||
{{/description}}
|
{{/description}}
|
||||||
"{{name}}": {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
|
'{{name}}': {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ export namespace {{classname}} {
|
|||||||
{{#vars}}
|
{{#vars}}
|
||||||
{{#isEnum}}
|
{{#isEnum}}
|
||||||
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
|
export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}}
|
||||||
VALUE_{{.}} = <any> '{{.}}'{{^-last}},{{/-last}}{{/values}}{{/allowableValues}}
|
{{datatypeWithEnum}}_{{.}} = <any> '{{.}}'{{^-last}},{{/-last}}{{/values}}{{/allowableValues}}
|
||||||
}
|
}
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
@ -184,7 +183,7 @@ export class {{classname}} {
|
|||||||
* {{notes}}
|
* {{notes}}
|
||||||
{{#allParams}}* @param {{paramName}} {{description}}
|
{{#allParams}}* @param {{paramName}} {{description}}
|
||||||
{{/allParams}}*/
|
{{/allParams}}*/
|
||||||
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
|
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.IncomingMessage; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
|
||||||
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
|
const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
|
||||||
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
|
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
|
||||||
let queryParameters: any = {};
|
let queryParameters: any = {};
|
||||||
@ -227,7 +226,7 @@ export class {{classname}} {
|
|||||||
{{#bodyParam}}
|
{{#bodyParam}}
|
||||||
body: {{paramName}},
|
body: {{paramName}},
|
||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
}
|
};
|
||||||
|
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
this.authentications.{{name}}.applyToRequest(requestOptions);
|
this.authentications.{{name}}.applyToRequest(requestOptions);
|
||||||
@ -243,7 +242,7 @@ export class {{classname}} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>((resolve, reject) => {
|
return new Promise<{ response: http.IncomingMessage; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }>((resolve, reject) => {
|
||||||
request(requestOptions, (error, response, body) => {
|
request(requestOptions, (error, response, body) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
|
@ -5,12 +5,13 @@
|
|||||||
"main": "api.js",
|
"main": "api.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "tsd reinstall --overwrite",
|
"postinstall": "tsd reinstall --overwrite",
|
||||||
"test": "tsc",
|
"test": "tsc --target ES6 && node client.js",
|
||||||
"clean": "rm -Rf node_modules/ typings/ *.js"
|
"clean": "rm -Rf node_modules/ typings/ *.js"
|
||||||
},
|
},
|
||||||
"author": "Mads M. Tandrup",
|
"author": "Mads M. Tandrup",
|
||||||
"license": "Apache 2.0",
|
"license": "Apache 2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"request": "^2.60.0",
|
||||||
"angular": "^1.4.3"
|
"angular": "^1.4.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -5,11 +5,20 @@
|
|||||||
"path": "typings",
|
"path": "typings",
|
||||||
"bundle": "typings/tsd.d.ts",
|
"bundle": "typings/tsd.d.ts",
|
||||||
"installed": {
|
"installed": {
|
||||||
"angularjs/angular.d.ts": {
|
"angularjs/angular.d.ts": {
|
||||||
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
|
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
|
||||||
},
|
},
|
||||||
"jquery/jquery.d.ts": {
|
"jquery/jquery.d.ts": {
|
||||||
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
|
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
|
||||||
|
},
|
||||||
|
"request/request.d.ts": {
|
||||||
|
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
|
||||||
|
},
|
||||||
|
"form-data/form-data.d.ts": {
|
||||||
|
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
|
||||||
|
},
|
||||||
|
"node/node.d.ts": {
|
||||||
|
"commit": "f6c8ca47193fb67947944a3170912672ac3e908e"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user