@@ -86,6 +86,7 @@ import { OpenAPI } from './OpenAPI';
86
86
function isDefined<T>(value: T | null | undefined): value is Exclude<T, null | undefined> {
87
87
return value !== undefined && value !== null;
88
88
}
89
+
89
90
function getQueryString(params: Record<string, any>): string {
90
91
const qs: string[] = [];
91
92
Object.keys(params).forEach(key => {
@@ -105,15 +106,17 @@ function getQueryString(params: Record<string, any>): string {
105
106
}
106
107
return '';
107
108
}
109
+
108
110
function getUrl(options: ApiRequestOptions): string {
109
111
const path = options.path.replace(/[:]/g, '_');
110
112
const url = \`\${OpenAPI.BASE}\${path}\`;
111
113
112
114
if (options.query) {
113
- return url + getQueryString(options.query);
115
+ return \`\${ url}\${ getQueryString(options.query)}\` ;
114
116
}
115
117
return url;
116
118
}
119
+
117
120
function getFormData(params: Record<string, any>): FormData {
118
121
const formData = new FormData();
119
122
Object.keys(params).forEach(key => {
@@ -124,6 +127,7 @@ function getFormData(params: Record<string, any>): FormData {
124
127
});
125
128
return formData;
126
129
}
130
+
127
131
function getHeaders(options: ApiRequestOptions): Headers {
128
132
const headers = new Headers({
129
133
Accept: 'application/json',
@@ -147,6 +151,7 @@ function getHeaders(options: ApiRequestOptions): Headers {
147
151
}
148
152
return headers;
149
153
}
154
+
150
155
function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
151
156
if (options.formData) {
152
157
return getFormData(options.formData);
@@ -162,6 +167,7 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
162
167
}
163
168
return undefined;
164
169
}
170
+
165
171
async function sendRequest(options: ApiRequestOptions, url: string): Promise<Response> {
166
172
const request: RequestInit = {
167
173
method: options.method,
@@ -170,6 +176,7 @@ async function sendRequest(options: ApiRequestOptions, url: string): Promise<Res
170
176
};
171
177
return await fetch(url, request);
172
178
}
179
+
173
180
function getResponseHeader(response: Response, responseHeader?: string): string | null {
174
181
if (responseHeader) {
175
182
const content = response.headers.get(responseHeader);
@@ -179,6 +186,7 @@ function getResponseHeader(response: Response, responseHeader?: string): string
179
186
}
180
187
return null;
181
188
}
189
+
182
190
async function getResponseBody(response: Response): Promise<any> {
183
191
try {
184
192
const contentType = response.headers.get('Content-Type');
@@ -196,6 +204,7 @@ async function getResponseBody(response: Response): Promise<any> {
196
204
}
197
205
return null;
198
206
}
207
+
199
208
function catchErrors(options: ApiRequestOptions, result: ApiResult): void {
200
209
const errors: Record<number, string> = {
201
210
400: 'Bad Request',
@@ -219,8 +228,8 @@ function catchErrors(options: ApiRequestOptions, result: ApiResult): void {
219
228
}
220
229
221
230
/**
222
- * Request using fetch
223
- * @param options Request options
231
+ * Request using fetch client
232
+ * @param options The request options from the the service
224
233
* @result ApiResult
225
234
* @throws ApiError
226
235
*/
@@ -2108,6 +2117,7 @@ import { OpenAPI } from './OpenAPI';
2108
2117
function isDefined<T>(value: T | null | undefined): value is Exclude<T, null | undefined> {
2109
2118
return value !== undefined && value !== null;
2110
2119
}
2120
+
2111
2121
function getQueryString(params: Record<string, any>): string {
2112
2122
const qs: string[] = [];
2113
2123
Object.keys(params).forEach(key => {
@@ -2127,15 +2137,17 @@ function getQueryString(params: Record<string, any>): string {
2127
2137
}
2128
2138
return '';
2129
2139
}
2140
+
2130
2141
function getUrl(options: ApiRequestOptions): string {
2131
2142
const path = options.path.replace(/[:]/g, '_');
2132
2143
const url = \`\${OpenAPI.BASE}\${path}\`;
2133
2144
2134
2145
if (options.query) {
2135
- return url + getQueryString(options.query);
2146
+ return \`\${ url}\${ getQueryString(options.query)}\` ;
2136
2147
}
2137
2148
return url;
2138
2149
}
2150
+
2139
2151
function getFormData(params: Record<string, any>): FormData {
2140
2152
const formData = new FormData();
2141
2153
Object.keys(params).forEach(key => {
@@ -2146,6 +2158,7 @@ function getFormData(params: Record<string, any>): FormData {
2146
2158
});
2147
2159
return formData;
2148
2160
}
2161
+
2149
2162
function getHeaders(options: ApiRequestOptions): Headers {
2150
2163
const headers = new Headers({
2151
2164
Accept: 'application/json',
@@ -2169,6 +2182,7 @@ function getHeaders(options: ApiRequestOptions): Headers {
2169
2182
}
2170
2183
return headers;
2171
2184
}
2185
+
2172
2186
function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
2173
2187
if (options.formData) {
2174
2188
return getFormData(options.formData);
@@ -2184,6 +2198,7 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
2184
2198
}
2185
2199
return undefined;
2186
2200
}
2201
+
2187
2202
async function sendRequest(options: ApiRequestOptions, url: string): Promise<Response> {
2188
2203
const request: RequestInit = {
2189
2204
method: options.method,
@@ -2192,6 +2207,7 @@ async function sendRequest(options: ApiRequestOptions, url: string): Promise<Res
2192
2207
};
2193
2208
return await fetch(url, request);
2194
2209
}
2210
+
2195
2211
function getResponseHeader(response: Response, responseHeader?: string): string | null {
2196
2212
if (responseHeader) {
2197
2213
const content = response.headers.get(responseHeader);
@@ -2201,6 +2217,7 @@ function getResponseHeader(response: Response, responseHeader?: string): string
2201
2217
}
2202
2218
return null;
2203
2219
}
2220
+
2204
2221
async function getResponseBody(response: Response): Promise<any> {
2205
2222
try {
2206
2223
const contentType = response.headers.get('Content-Type');
@@ -2218,6 +2235,7 @@ async function getResponseBody(response: Response): Promise<any> {
2218
2235
}
2219
2236
return null;
2220
2237
}
2238
+
2221
2239
function catchErrors(options: ApiRequestOptions, result: ApiResult): void {
2222
2240
const errors: Record<number, string> = {
2223
2241
400: 'Bad Request',
@@ -2241,8 +2259,8 @@ function catchErrors(options: ApiRequestOptions, result: ApiResult): void {
2241
2259
}
2242
2260
2243
2261
/**
2244
- * Request using fetch
2245
- * @param options Request options
2262
+ * Request using fetch client
2263
+ * @param options The request options from the the service
2246
2264
* @result ApiResult
2247
2265
* @throws ApiError
2248
2266
*/
0 commit comments