-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiTest.service.ts
251 lines (214 loc) · 8.28 KB
/
apiTest.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/* tslint:disable */
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v12.0.4.0 (NJsonSchema v9.12.7.0 (Newtonsoft.Json v11.0.0.0)) (http://NSwag.org)
// </auto-generated>
//----------------------
// ReSharper disable InconsistentNaming
import { mergeMap as _observableMergeMap, catchError as _observableCatch } from 'rxjs/operators';
import { Observable, throwError as _observableThrow, of as _observableOf } from 'rxjs';
import { Injectable, Inject, Optional, InjectionToken } from '@angular/core';
import { HttpClient, HttpHeaders, HttpResponse, HttpResponseBase } from '@angular/common/http';
export const API_BASE_URL = new InjectionToken<string>('API_BASE_URL');
export interface IValuesClient {
index(randomInheritenceOfDad: Dad): Observable<string | null>;
}
@Injectable()
export class ValuesClient implements IValuesClient {
private http: HttpClient;
private baseUrl: string;
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
constructor(@Inject(HttpClient) http: HttpClient, @Optional() @Inject(API_BASE_URL) baseUrl?: string) {
this.http = http;
this.baseUrl = baseUrl ? baseUrl : "http://localhost:5000";
}
index(randomInheritenceOfDad: Dad): Observable<string | null> {
let url_ = this.baseUrl + "/";
url_ = url_.replace(/[?&]$/, "");
const content_ = JSON.stringify(randomInheritenceOfDad);
let options_ : any = {
body: content_,
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
"Content-Type": "application/json",
"Accept": "application/json"
})
};
return this.http.request("post", url_, options_).pipe(_observableMergeMap((response_ : any) => {
return this.processIndex(response_);
})).pipe(_observableCatch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processIndex(<any>response_);
} catch (e) {
return <Observable<string | null>><any>_observableThrow(e);
}
} else
return <Observable<string | null>><any>_observableThrow(response_);
}));
}
protected processIndex(response: HttpResponseBase): Observable<string | null> {
const status = response.status;
const responseBlob =
response instanceof HttpResponse ? response.body :
(<any>response).error instanceof Blob ? (<any>response).error : undefined;
let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }};
if (status === 200) {
return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 !== undefined ? resultData200 : <any>null;
return _observableOf(result200);
}));
} else if (status !== 200 && status !== 204) {
return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}));
}
return _observableOf<string | null>(<any>null);
}
}
export abstract class Dad implements IDad {
dadProp?: number;
dadRandomClassDto?: RandomClass | undefined;
protected _discriminator: string;
constructor(data?: IDad) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
this.dadRandomClassDto = data.dadRandomClassDto && !(<any>data.dadRandomClassDto).toJSON ? new RandomClass(data.dadRandomClassDto) : <RandomClass>this.dadRandomClassDto;
}
this._discriminator = "Dad";
}
init(data?: any) {
if (data) {
this.dadProp = data["dadProp"];
this.dadRandomClassDto = data["dadRandomClassDto"] ? RandomClass.fromJS(data["dadRandomClassDto"]) : <any>undefined;
}
}
static fromJS(data: any): Dad {
data = typeof data === 'object' ? data : {};
if (data["discriminator"] === "Son") {
let result = new Son();
result.init(data);
return result;
}
throw new Error("The abstract class 'Dad' cannot be instantiated.");
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["discriminator"] = this._discriminator;
data["dadProp"] = this.dadProp;
data["dadRandomClassDto"] = this.dadRandomClassDto ? this.dadRandomClassDto.toJSON() : <any>undefined;
return data;
}
}
export interface IDad {
dadProp?: number;
dadRandomClassDto?: IRandomClass | undefined;
}
export class RandomClass implements IRandomClass {
randomProp?: number;
constructor(data?: IRandomClass) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(data?: any) {
if (data) {
this.randomProp = data["randomProp"];
}
}
static fromJS(data: any): RandomClass {
data = typeof data === 'object' ? data : {};
let result = new RandomClass();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["randomProp"] = this.randomProp;
return data;
}
}
export interface IRandomClass {
randomProp?: number;
}
export class Son extends Dad implements ISon {
sonProp?: number;
sonRandomClassDto?: RandomClass | undefined;
constructor(data?: ISon) {
super(data);
this._discriminator = "Son";
}
init(data?: any) {
super.init(data);
if (data) {
this.sonProp = data["sonProp"];
this.sonRandomClassDto = data["sonRandomClassDto"] ? RandomClass.fromJS(data["sonRandomClassDto"]) : <any>undefined;
}
}
static fromJS(data: any): Son {
data = typeof data === 'object' ? data : {};
let result = new Son();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["sonProp"] = this.sonProp;
data["sonRandomClassDto"] = this.sonRandomClassDto ? this.sonRandomClassDto.toJSON() : <any>undefined;
super.toJSON(data);
return data;
}
}
export interface ISon extends IDad {
sonProp?: number;
sonRandomClassDto?: IRandomClass | undefined;
}
export class SwaggerException extends Error {
message: string;
status: number;
response: string;
headers: { [key: string]: any; };
result: any;
constructor(message: string, status: number, response: string, headers: { [key: string]: any; }, result: any) {
super();
this.message = message;
this.status = status;
this.response = response;
this.headers = headers;
this.result = result;
}
protected isSwaggerException = true;
static isSwaggerException(obj: any): obj is SwaggerException {
return obj.isSwaggerException === true;
}
}
function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): Observable<any> {
if(result !== null && result !== undefined)
return _observableThrow(result);
else
return _observableThrow(new SwaggerException(message, status, response, headers, null));
}
function blobToText(blob: any): Observable<string> {
return new Observable<string>((observer: any) => {
if (!blob) {
observer.next("");
observer.complete();
} else {
let reader = new FileReader();
reader.onload = event => {
observer.next((<any>event.target).result);
observer.complete();
};
reader.readAsText(blob);
}
});
}