Skip to content

Commit 5c6be5c

Browse files
authored
replace tab with spaces, minor code format change (#8775)
1 parent 4e7a0ef commit 5c6be5c

11 files changed

+155
-167
lines changed

api/api.mustache

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import { {{classname}} } from '..{{filename}}{{extensionForDeno}}';
2626
@injectable()
2727
{{/useInversify}}
2828
export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
29-
30-
{{#operation}}
29+
30+
{{#operation}}
3131
/**
3232
{{#notes}}
3333
* {{&notes}}
@@ -40,44 +40,44 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
4040
{{/allParams}}
4141
*/
4242
public async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: Configuration): Promise<RequestContext> {
43-
let config = options || this.configuration;
44-
{{#allParams}}
45-
46-
{{#required}}
43+
let config = options || this.configuration;
44+
{{#allParams}}
45+
46+
{{#required}}
4747
// verify required parameter '{{paramName}}' is not null or undefined
4848
if ({{paramName}} === null || {{paramName}} === undefined) {
4949
throw new RequiredError('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.');
5050
}
5151

52-
{{/required}}
53-
{{/allParams}}
54-
55-
// Path Params
56-
const localVarPath = '{{{path}}}'{{#pathParams}}
52+
{{/required}}
53+
{{/allParams}}
54+
55+
// Path Params
56+
const localVarPath = '{{{path}}}'{{#pathParams}}
5757
.replace('{' + '{{baseName}}' + '}', encodeURIComponent(String({{paramName}}))){{/pathParams}};
5858

59-
// Make Request Context
60-
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.{{httpMethod}});
59+
// Make Request Context
60+
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.{{httpMethod}});
6161
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
6262

6363
// Query Params
64-
{{#queryParams}}
64+
{{#queryParams}}
6565
if ({{paramName}} !== undefined) {
66-
requestContext.setQueryParam("{{baseName}}", ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"));
66+
requestContext.setQueryParam("{{baseName}}", ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"));
6767
}
68-
{{/queryParams}}
69-
70-
// Header Params
71-
{{#headerParams}}
72-
requestContext.setHeaderParam("{{baseName}}", ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"));
73-
{{/headerParams}}
74-
75-
// Form Params
76-
{{#hasFormParams}}
77-
let localVarFormParams = new FormData();
78-
{{/hasFormParams}}
79-
80-
{{#formParams}}
68+
{{/queryParams}}
69+
70+
// Header Params
71+
{{#headerParams}}
72+
requestContext.setHeaderParam("{{baseName}}", ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"));
73+
{{/headerParams}}
74+
75+
// Form Params
76+
{{#hasFormParams}}
77+
let localVarFormParams = new FormData();
78+
{{/hasFormParams}}
79+
80+
{{#formParams}}
8181
{{#isArray}}
8282
if ({{paramName}}) {
8383
{{#isCollectionFormatMulti}}
@@ -86,14 +86,14 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
8686
})
8787
{{/isCollectionFormatMulti}}
8888
{{^isCollectionFormatMulti}}
89-
// TODO: replace .append with .set
90-
localVarFormParams.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
89+
// TODO: replace .append with .set
90+
localVarFormParams.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
9191
{{/isCollectionFormatMulti}}
9292
}
9393
{{/isArray}}
9494
{{^isArray}}
9595
if ({{paramName}} !== undefined) {
96-
// TODO: replace .append with .set
96+
// TODO: replace .append with .set
9797
{{^isFile}}
9898
localVarFormParams.append('{{baseName}}', {{paramName}} as any);
9999
{{/isFile}}
@@ -109,13 +109,13 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
109109
{{/isFile}}
110110
}
111111
{{/isArray}}
112-
{{/formParams}}
113-
{{#hasFormParams}}
114-
requestContext.setBody(localVarFormParams);
115-
{{/hasFormParams}}
112+
{{/formParams}}
113+
{{#hasFormParams}}
114+
requestContext.setBody(localVarFormParams);
115+
{{/hasFormParams}}
116116

117-
// Body Params
118-
{{#bodyParam}}
117+
// Body Params
118+
{{#bodyParam}}
119119
const contentType = ObjectSerializer.getPreferredMediaType([{{#consumes}}
120120
"{{{mediaType}}}"{{^-last}},{{/-last}}
121121
{{/consumes}}]);
@@ -125,7 +125,7 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
125125
contentType
126126
);
127127
requestContext.setBody(serializedBody);
128-
{{/bodyParam}}
128+
{{/bodyParam}}
129129

130130
{{#hasAuthMethods}}
131131
let authMethod = null;
@@ -144,8 +144,6 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
144144
{{/operation}}
145145
}
146146
{{/operations}}
147-
148-
149147
{{#operations}}
150148

151149
{{#useInversify}}
@@ -213,9 +211,9 @@ export class {{classname}}ResponseProcessor {
213211
}
214212

215213
let body = response.body || "";
216-
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
214+
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
217215
}
218-
219-
{{/operation}}
216+
217+
{{/operation}}
220218
}
221219
{{/operations}}

api/exception.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*/
1010
export class ApiException<T> extends Error {
11-
public constructor(public code: number, public body: T) {
11+
public constructor(public code: number, public body: T) {
1212
super("HTTP-Code: " + code + "\nMessage: " + JSON.stringify(body))
13-
}
14-
}
13+
}
14+
}

api/middleware.mustache

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { Observable, from } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'./rx
88
*
99
*/
1010
export interface Middleware {
11-
/**
12-
* Modifies the request before the request is sent.
13-
*
14-
* @param context RequestContext of a request which is about to be sent to the server
15-
* @returns an observable of the updated request context
16-
*
17-
*/
11+
/**
12+
* Modifies the request before the request is sent.
13+
*
14+
* @param context RequestContext of a request which is about to be sent to the server
15+
* @returns an observable of the updated request context
16+
*
17+
*/
1818
pre(context: RequestContext): Observable<RequestContext>;
1919
/**
2020
* Modifies the returned response before it is deserialized.
@@ -48,13 +48,13 @@ export class PromiseMiddlewareWrapper implements Middleware {
4848
*
4949
*/
5050
export interface PromiseMiddleware {
51-
/**
52-
* Modifies the request before the request is sent.
53-
*
54-
* @param context RequestContext of a request which is about to be sent to the server
55-
* @returns an observable of the updated request context
56-
*
57-
*/
51+
/**
52+
* Modifies the request before the request is sent.
53+
*
54+
* @param context RequestContext of a request which is about to be sent to the server
55+
* @returns an observable of the updated request context
56+
*
57+
*/
5858
pre(context: RequestContext): Promise<RequestContext>;
5959
/**
6060
* Modifies the returned response before it is deserialized.
@@ -63,4 +63,4 @@ export interface PromiseMiddleware {
6363
* @returns an observable of the modified response context
6464
*/
6565
post(context: ResponseContext): Promise<ResponseContext>;
66-
}
66+
}

http/http.mustache

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ export type HttpFile = {{{fileContentDataType}}} & { readonly name: string };
6363
*/
6464
class URLParse {
6565
private url: URL;
66+
6667
constructor(address: string, _parser: boolean) {
6768
this.url = new URL(address);
6869
}
70+
6971
public set(_part: 'query', obj: {[key: string]: string | undefined}) {
7072
for (const key in obj) {
7173
const value = obj[key];
@@ -76,13 +78,15 @@ class URLParse {
7678
}
7779
}
7880
}
81+
7982
public get query() {
8083
const obj: {[key: string]: string} = {};
8184
for (const [key, value] of this.url.searchParams.entries()) {
8285
obj[key] = value;
8386
}
8487
return obj;
8588
}
89+
8690
public toString() {
8791
return this.url.toString();
8892
}
@@ -109,24 +113,24 @@ export class RequestContext {
109113
private body: RequestBody = undefined;
110114
private url: URLParse;
111115

112-
/**
113-
* Creates the request context using a http method and request resource url
114-
*
115-
* @param url url of the requested resource
116-
* @param httpMethod http method
117-
*/
116+
/**
117+
* Creates the request context using a http method and request resource url
118+
*
119+
* @param url url of the requested resource
120+
* @param httpMethod http method
121+
*/
118122
public constructor(url: string, private httpMethod: HttpMethod) {
119123
this.url = new URLParse(url, true);
120124
}
121-
125+
122126
/*
123127
* Returns the url set in the constructor including the query string
124128
*
125129
*/
126130
public getUrl(): string {
127-
return this.url.toString();
131+
return this.url.toString();
128132
}
129-
133+
130134
/**
131135
* Replaces the url set in the constructor with this url.
132136
*
@@ -149,27 +153,27 @@ export class RequestContext {
149153
}
150154

151155
public getHttpMethod(): HttpMethod {
152-
return this.httpMethod;
156+
return this.httpMethod;
153157
}
154-
158+
155159
public getHeaders(): { [key: string]: string } {
156-
return this.headers;
160+
return this.headers;
157161
}
158162

159163
public getBody(): RequestBody {
160164
return this.body;
161165
}
162166

163-
public setQueryParam(name: string, value: string) {
167+
public setQueryParam(name: string, value: string) {
164168
let queryObj = this.url.query;
165169
queryObj[name] = value;
166170
this.url.set("query", queryObj);
167171
}
168172

169-
/**
170-
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
171-
*
172-
*/
173+
/**
174+
* Sets a cookie with the name and value. NO check for duplicate cookies is performed
175+
*
176+
*/
173177
public addCookie(name: string, value: string): void {
174178
if (!this.headers["Cookie"]) {
175179
this.headers["Cookie"] = "";
@@ -187,7 +191,6 @@ export interface ResponseBody {
187191
binary(): Promise<{{{fileContentDataType}}}>;
188192
}
189193

190-
191194
/**
192195
* Helper class to generate a `ResponseBody` from binary data
193196
*/
@@ -299,4 +302,4 @@ export function wrapHttpLibrary(promiseHttpLibrary: PromiseHttpLibrary): HttpLib
299302
return from(promiseHttpLibrary.send(request));
300303
}
301304
}
302-
}
305+
}

http/jquery.mustache

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ export class JQueryHttpLibrary implements HttpLibrary {
2121
data: body
2222
};
2323

24-
// If we want a blob, we have to set the xhrFields' responseType AND add a
25-
// custom converter to overwrite the default deserialization of JQuery...
24+
// If we want a blob, we have to set the xhrFields' responseType AND add a
25+
// custom converter to overwrite the default deserialization of JQuery...
2626
requestOptions["xhrFields"] = { responseType: 'blob' };
2727
requestOptions["converters"] = {}
2828
requestOptions["converters"]["* blob"] = (result:any) => result;
2929
requestOptions["dataType"] = "blob";
3030

31-
3231
if (request.getHeaders()['Content-Type']) {
3332
requestOptions.contentType = headerParams['Content-Type'];
3433
}
@@ -41,17 +40,17 @@ export class JQueryHttpLibrary implements HttpLibrary {
4140
}
4241
}
4342
})(headerParams);
44-
43+
4544
if (request.getHeaders()["Cookie"]) {
4645
throw new HttpException("Setting the \"Cookie\"-Header field is blocked by every major browser when using jquery.ajax requests. Please switch to another library like fetch to enable this option");
4746
}
4847

4948
if (body && body.constructor.name == "FormData") {
5049
requestOptions.contentType = false;
5150
}
52-
51+
5352
const sentRequest = $.ajax(requestOptions);
54-
53+
5554
const resultPromise = new Promise<ResponseContext>((resolve, reject) => {
5655
sentRequest.done((data, _, jqXHR) => {
5756
const result = new ResponseContext(
@@ -65,7 +64,7 @@ export class JQueryHttpLibrary implements HttpLibrary {
6564
const headers = this.getResponseHeaders(jqXHR)
6665
const result = new ResponseContext(jqXHR.status, headers, jqXHR.responseText);
6766
resolve(result);
68-
})
67+
})
6968
})
7069
return from(resultPromise);
7170
}
@@ -79,7 +78,7 @@ export class JQueryHttpLibrary implements HttpLibrary {
7978
var key = header.shift();
8079
if (key.length == 0) return
8180
// chrome60+ force lowercase, other browsers can be different
82-
key = key.toLowerCase();
81+
key = key.toLowerCase();
8382
responseHeaders[key] = header.join(": ");
8483
});
8584
return responseHeaders

0 commit comments

Comments
 (0)