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