replace tab with 4space for ts jquery client (#5299)

This commit is contained in:
wing328 2017-04-03 15:48:51 +08:00 committed by GitHub
parent 7db3388fdc
commit e5b3e3cdac
4 changed files with 2351 additions and 2351 deletions

View File

@ -11,18 +11,18 @@ let defaultBasePath = '{{{basePath}}}';
{{#models}} {{#models}}
{{#model}} {{#model}}
{{#description}} {{#description}}
/** /**
* {{{description}}} * {{{description}}}
*/ */
{{/description}} {{/description}}
export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
{{#vars}} {{#vars}}
{{#description}} {{#description}}
/** /**
* {{{description}}} * {{{description}}}
*/ */
{{/description}} {{/description}}
'{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; '{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
{{/vars}} {{/vars}}
} }
@ -30,13 +30,13 @@ export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
export namespace {{classname}} { export namespace {{classname}} {
{{#vars}} {{#vars}}
{{#isEnum}} {{#isEnum}}
export enum {{enumName}} { export enum {{enumName}} {
{{#allowableValues}} {{#allowableValues}}
{{#enumVars}} {{#enumVars}}
{{name}} = <any> {{{value}}}{{^-last}},{{/-last}} {{name}} = <any> {{{value}}}{{^-last}},{{/-last}}
{{/enumVars}} {{/enumVars}}
{{/allowableValues}} {{/allowableValues}}
} }
{{/isEnum}} {{/isEnum}}
{{/vars}} {{/vars}}
} }
@ -45,46 +45,46 @@ export namespace {{classname}} {
{{/models}} {{/models}}
export interface Authentication { export interface Authentication {
/** /**
* Apply authentication settings to header and query params. * Apply authentication settings to header and query params.
*/ */
applyToRequest(requestOptions: JQueryAjaxSettings): void; applyToRequest(requestOptions: JQueryAjaxSettings): void;
} }
export class HttpBasicAuth implements Authentication { export class HttpBasicAuth implements Authentication {
public username: string; public username: string;
public password: string; public password: string;
applyToRequest(requestOptions: any): void { applyToRequest(requestOptions: any): void {
requestOptions.username = this.username; requestOptions.username = this.username;
requestOptions.password = this.password; requestOptions.password = this.password;
} }
} }
export class ApiKeyAuth implements Authentication { export class ApiKeyAuth implements Authentication {
public apiKey: string; public apiKey: string;
constructor(private location: string, private paramName: string) { constructor(private location: string, private paramName: string) {
} }
applyToRequest(requestOptions: JQueryAjaxSettings): void { applyToRequest(requestOptions: JQueryAjaxSettings): void {
requestOptions.headers[this.paramName] = this.apiKey; requestOptions.headers[this.paramName] = this.apiKey;
} }
} }
export class OAuth implements Authentication { export class OAuth implements Authentication {
public accessToken: string; public accessToken: string;
applyToRequest(requestOptions: JQueryAjaxSettings): void { applyToRequest(requestOptions: JQueryAjaxSettings): void {
requestOptions.headers["Authorization"] = "Bearer " + this.accessToken; requestOptions.headers["Authorization"] = "Bearer " + this.accessToken;
} }
} }
export class VoidAuth implements Authentication { export class VoidAuth implements Authentication {
public username: string; public username: string;
public password: string; public password: string;
applyToRequest(requestOptions: JQueryAjaxSettings): void { applyToRequest(requestOptions: JQueryAjaxSettings): void {
// Do nothing // Do nothing
} }
} }
{{#apiInfo}} {{#apiInfo}}
@ -98,170 +98,170 @@ export class VoidAuth implements Authentication {
export enum {{classname}}ApiKeys { export enum {{classname}}ApiKeys {
{{#authMethods}} {{#authMethods}}
{{#isApiKey}} {{#isApiKey}}
{{name}}, {{name}},
{{/isApiKey}} {{/isApiKey}}
{{/authMethods}} {{/authMethods}}
} }
export class {{classname}} { export class {{classname}} {
protected basePath = defaultBasePath; protected basePath = defaultBasePath;
protected defaultHeaders : any = {}; protected defaultHeaders : any = {};
protected authentications = { protected authentications = {
'default': <Authentication>new VoidAuth(), 'default': <Authentication>new VoidAuth(),
{{#authMethods}} {{#authMethods}}
{{#isBasic}} {{#isBasic}}
'{{name}}': new HttpBasicAuth(), '{{name}}': new HttpBasicAuth(),
{{/isBasic}} {{/isBasic}}
{{#isApiKey}} {{#isApiKey}}
'{{name}}': new ApiKeyAuth({{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}, '{{keyParamName}}'), '{{name}}': new ApiKeyAuth({{#isKeyInHeader}}'header'{{/isKeyInHeader}}{{^isKeyInHeader}}'query'{{/isKeyInHeader}}, '{{keyParamName}}'),
{{/isApiKey}} {{/isApiKey}}
{{#isOAuth}} {{#isOAuth}}
'{{name}}': new OAuth(), '{{name}}': new OAuth(),
{{/isOAuth}} {{/isOAuth}}
{{/authMethods}} {{/authMethods}}
} }
constructor(basePath?: string); constructor(basePath?: string);
{{#authMethods}} {{#authMethods}}
{{#isBasic}} {{#isBasic}}
constructor(username: string, password: string, basePath?: string); constructor(username: string, password: string, basePath?: string);
{{/isBasic}} {{/isBasic}}
{{/authMethods}} {{/authMethods}}
constructor(basePathOrUsername: string, password?: string, basePath?: string) { constructor(basePathOrUsername: string, password?: string, basePath?: string) {
if (password) { if (password) {
{{#authMethods}} {{#authMethods}}
{{#isBasic}} {{#isBasic}}
this.username = basePathOrUsername; this.username = basePathOrUsername;
this.password = password this.password = password
{{/isBasic}} {{/isBasic}}
{{/authMethods}} {{/authMethods}}
if (basePath) { if (basePath) {
this.basePath = basePath; this.basePath = basePath;
} }
} else { } else {
if (basePathOrUsername) { if (basePathOrUsername) {
this.basePath = basePathOrUsername this.basePath = basePathOrUsername
} }
} }
} }
public setApiKey(key: {{classname}}ApiKeys, value: string) { public setApiKey(key: {{classname}}ApiKeys, value: string) {
this.authentications[{{classname}}ApiKeys[key]].apiKey = value; this.authentications[{{classname}}ApiKeys[key]].apiKey = value;
} }
{{#authMethods}} {{#authMethods}}
{{#isBasic}} {{#isBasic}}
set username(username: string) { set username(username: string) {
this.authentications.{{name}}.username = username; this.authentications.{{name}}.username = username;
} }
set password(password: string) { set password(password: string) {
this.authentications.{{name}}.password = password; this.authentications.{{name}}.password = password;
} }
{{/isBasic}} {{/isBasic}}
{{#isOAuth}} {{#isOAuth}}
set accessToken(token: string) { set accessToken(token: string) {
this.authentications.{{name}}.accessToken = token; this.authentications.{{name}}.accessToken = token;
} }
{{/isOAuth}} {{/isOAuth}}
{{/authMethods}} {{/authMethods}}
private extendObj<T1, T2 extends T1>(objA: T2, objB: T2): T1|T2 { private extendObj<T1, T2 extends T1>(objA: T2, objB: T2): T1|T2 {
for(let key in objB){ for(let key in objB){
if(objB.hasOwnProperty(key)){ if(objB.hasOwnProperty(key)){
objA[key] = objB[key]; objA[key] = objB[key];
} }
} }
return objA; return objA;
} }
{{#operation}} {{#operation}}
/** /**
* {{summary}} * {{summary}}
* {{notes}} * {{notes}}
{{#allParams}}* @param {{paramName}} {{description}} {{#allParams}}* @param {{paramName}} {{description}}
{{/allParams}}*/ {{/allParams}}*/
public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : JQueryPromise<{ response: JQueryXHR; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : JQueryPromise<{ response: JQueryXHR; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> {
let localVarPath = this.basePath + '{{{path}}}'{{#pathParams}} let localVarPath = this.basePath + '{{{path}}}'{{#pathParams}}
.replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};
let queryParameters: any = {}; let queryParameters: any = {};
let headerParams: any = this.extendObj({}, this.defaultHeaders); let headerParams: any = this.extendObj({}, this.defaultHeaders);
{{#allParams}}{{#required}} {{#allParams}}{{#required}}
// verify required parameter '{{paramName}}' is not null or undefined // verify required parameter '{{paramName}}' is not null or undefined
if ({{paramName}} === null || {{paramName}} === undefined) { if ({{paramName}} === null || {{paramName}} === undefined) {
throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.'); throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.');
} }
{{/required}}{{/allParams}} {{/required}}{{/allParams}}
{{#queryParams}} {{#queryParams}}
if ({{paramName}} !== undefined) { if ({{paramName}} !== undefined) {
queryParameters['{{baseName}}'] = {{paramName}}; queryParameters['{{baseName}}'] = {{paramName}};
} }
{{/queryParams}} {{/queryParams}}
localVarPath = localVarPath + "?" + $.param(queryParameters); localVarPath = localVarPath + "?" + $.param(queryParameters);
{{#headerParams}} {{#headerParams}}
headerParams['{{baseName}}'] = {{paramName}}; headerParams['{{baseName}}'] = {{paramName}};
{{/headerParams}} {{/headerParams}}
{{^bodyParam}} {{^bodyParam}}
let reqHasFile = false; let reqHasFile = false;
let reqDict = {}; let reqDict = {};
let reqFormData = new FormData(); let reqFormData = new FormData();
{{#formParams}} {{#formParams}}
{{#isFile}} {{#isFile}}
reqHasFile = true; reqHasFile = true;
{{/isFile}} {{/isFile}}
if ({{paramName}} !== undefined) { if ({{paramName}} !== undefined) {
reqFormData.append('{{baseName}}', {{paramName}}); reqFormData.append('{{baseName}}', {{paramName}});
reqDict['{{baseName}}'] = {{paramName}}; reqDict['{{baseName}}'] = {{paramName}};
} }
{{/formParams}} {{/formParams}}
{{/bodyParam}} {{/bodyParam}}
{{#bodyParam}} {{#bodyParam}}
let reqDict = {{paramName}}; let reqDict = {{paramName}};
let reqFormData = new FormData(); let reqFormData = new FormData();
reqFormData.append('{{paramName}}', {{paramName}}); reqFormData.append('{{paramName}}', {{paramName}});
{{#isFile}} {{#isFile}}
let reqHasFile = true; let reqHasFile = true;
{{/isFile}} {{/isFile}}
{{^isFile}} {{^isFile}}
let reqHasFile = false; let reqHasFile = false;
{{/isFile}} {{/isFile}}
{{/bodyParam}} {{/bodyParam}}
let requestOptions: JQueryAjaxSettings = { let requestOptions: JQueryAjaxSettings = {
url: localVarPath, url: localVarPath,
type: '{{httpMethod}}', type: '{{httpMethod}}',
headers: headerParams, headers: headerParams,
processData: false processData: false
}; };
if (Object.keys(reqDict).length) { if (Object.keys(reqDict).length) {
requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict); requestOptions.data = reqHasFile ? reqFormData : JSON.stringify(reqDict);
requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8'; requestOptions.contentType = reqHasFile ? false : 'application/json; charset=utf-8';
} }
{{#authMethods}} {{#authMethods}}
this.authentications.{{name}}.applyToRequest(requestOptions); this.authentications.{{name}}.applyToRequest(requestOptions);
{{/authMethods}} {{/authMethods}}
this.authentications.default.applyToRequest(requestOptions); this.authentications.default.applyToRequest(requestOptions);
let dfd = $.Deferred(); let dfd = $.Deferred();
$.ajax(requestOptions).then( $.ajax(requestOptions).then(
(data: {{{returnType}}}, textStatus: string, jqXHR: JQueryXHR) => (data: {{{returnType}}}, textStatus: string, jqXHR: JQueryXHR) =>
dfd.resolve({ response: jqXHR, body: data }), dfd.resolve({ response: jqXHR, body: data }),
(xhr: JQueryXHR, textStatus: string, errorThrown: string) => (xhr: JQueryXHR, textStatus: string, errorThrown: string) =>
dfd.reject({ response: xhr, body: errorThrown }) dfd.reject({ response: xhr, body: errorThrown })
); );
return dfd.promise(); return dfd.promise();
} }
{{/operation}} {{/operation}}
} }
{{/operations}} {{/operations}}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@swagger/angular2-typescript-petstore", "name": "@swagger/angular2-typescript-petstore",
"version": "0.0.1-SNAPSHOT.201703061507", "version": "0.0.1-SNAPSHOT.201704021610",
"description": "JQuery client for @swagger/angular2-typescript-petstore", "description": "JQuery client for @swagger/angular2-typescript-petstore",
"main": "api.js", "main": "api.js",
"scripts": { "scripts": {