Skip to content

Commit 8c9706e

Browse files
committed
Update vitest snapshot
Signed-off-by: Sora Morimoto <[email protected]>
1 parent 40efa18 commit 8c9706e

File tree

1 file changed

+0
-243
lines changed

1 file changed

+0
-243
lines changed

tests/spec/unionEnums/__snapshots__/basic.test.ts.snap

Lines changed: 0 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -242,246 +242,3 @@ export class HttpClient<SecurityDataType = unknown> {
242242
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {}
243243
"
244244
`;
245-
246-
exports[`basic > --union-enums 1`] = `
247-
"/* eslint-disable */
248-
/* tslint:disable */
249-
// @ts-nocheck
250-
/*
251-
* ---------------------------------------------------------------
252-
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
253-
* ## ##
254-
* ## AUTHOR: acacode ##
255-
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
256-
* ---------------------------------------------------------------
257-
*/
258-
259-
export type StringEnum = "String1" | "String2" | "String3" | "String4";
260-
261-
export type NumberEnum = 1 | 2 | 3 | 4;
262-
263-
export type BooleanEnum = true | false;
264-
265-
/**
266-
* FooBar
267-
* @format int32
268-
*/
269-
export type IntEnumWithNames = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
270-
271-
export type QueryParamsType = Record<string | number, any>;
272-
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
273-
274-
export interface FullRequestParams extends Omit<RequestInit, "body"> {
275-
/** set parameter to \`true\` for call \`securityWorker\` for this request */
276-
secure?: boolean;
277-
/** request path */
278-
path: string;
279-
/** content type of request body */
280-
type?: ContentType;
281-
/** query params */
282-
query?: QueryParamsType;
283-
/** format of response (i.e. response.json() -> format: "json") */
284-
format?: ResponseFormat;
285-
/** request body */
286-
body?: unknown;
287-
/** base url */
288-
baseUrl?: string;
289-
/** request cancellation token */
290-
cancelToken?: CancelToken;
291-
}
292-
293-
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
294-
295-
export interface ApiConfig<SecurityDataType = unknown> {
296-
baseUrl?: string;
297-
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
298-
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
299-
customFetch?: typeof fetch;
300-
}
301-
302-
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
303-
data: D;
304-
error: E;
305-
}
306-
307-
type CancelToken = Symbol | string | number;
308-
309-
export enum ContentType {
310-
Json = "application/json",
311-
FormData = "multipart/form-data",
312-
UrlEncoded = "application/x-www-form-urlencoded",
313-
Text = "text/plain",
314-
}
315-
316-
export class HttpClient<SecurityDataType = unknown> {
317-
public baseUrl: string = "http://localhost:8080/api/v1";
318-
private securityData: SecurityDataType | null = null;
319-
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"];
320-
private abortControllers = new Map<CancelToken, AbortController>();
321-
private customFetch = (...fetchParams: Parameters<typeof fetch>) => fetch(...fetchParams);
322-
323-
private baseApiParams: RequestParams = {
324-
credentials: "same-origin",
325-
headers: {},
326-
redirect: "follow",
327-
referrerPolicy: "no-referrer",
328-
};
329-
330-
constructor(apiConfig: ApiConfig<SecurityDataType> = {}) {
331-
Object.assign(this, apiConfig);
332-
}
333-
334-
public setSecurityData = (data: SecurityDataType | null) => {
335-
this.securityData = data;
336-
};
337-
338-
protected encodeQueryParam(key: string, value: any) {
339-
const encodedKey = encodeURIComponent(key);
340-
return \`\${encodedKey}=\${encodeURIComponent(typeof value === "number" ? value : \`\${value}\`)}\`;
341-
}
342-
343-
protected addQueryParam(query: QueryParamsType, key: string) {
344-
return this.encodeQueryParam(key, query[key]);
345-
}
346-
347-
protected addArrayQueryParam(query: QueryParamsType, key: string) {
348-
const value = query[key];
349-
return value.map((v: any) => this.encodeQueryParam(key, v)).join("&");
350-
}
351-
352-
protected toQueryString(rawQuery?: QueryParamsType): string {
353-
const query = rawQuery || {};
354-
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
355-
return keys
356-
.map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)))
357-
.join("&");
358-
}
359-
360-
protected addQueryParams(rawQuery?: QueryParamsType): string {
361-
const queryString = this.toQueryString(rawQuery);
362-
return queryString ? \`?\${queryString}\` : "";
363-
}
364-
365-
private contentFormatters: Record<ContentType, (input: any) => any> = {
366-
[ContentType.Json]: (input: any) =>
367-
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
368-
[ContentType.Text]: (input: any) => (input !== null && typeof input !== "string" ? JSON.stringify(input) : input),
369-
[ContentType.FormData]: (input: any) =>
370-
Object.keys(input || {}).reduce((formData, key) => {
371-
const property = input[key];
372-
formData.append(
373-
key,
374-
property instanceof Blob
375-
? property
376-
: typeof property === "object" && property !== null
377-
? JSON.stringify(property)
378-
: \`\${property}\`,
379-
);
380-
return formData;
381-
}, new FormData()),
382-
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
383-
};
384-
385-
protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams {
386-
return {
387-
...this.baseApiParams,
388-
...params1,
389-
...(params2 || {}),
390-
headers: {
391-
...(this.baseApiParams.headers || {}),
392-
...(params1.headers || {}),
393-
...((params2 && params2.headers) || {}),
394-
},
395-
};
396-
}
397-
398-
protected createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => {
399-
if (this.abortControllers.has(cancelToken)) {
400-
const abortController = this.abortControllers.get(cancelToken);
401-
if (abortController) {
402-
return abortController.signal;
403-
}
404-
return void 0;
405-
}
406-
407-
const abortController = new AbortController();
408-
this.abortControllers.set(cancelToken, abortController);
409-
return abortController.signal;
410-
};
411-
412-
public abortRequest = (cancelToken: CancelToken) => {
413-
const abortController = this.abortControllers.get(cancelToken);
414-
415-
if (abortController) {
416-
abortController.abort();
417-
this.abortControllers.delete(cancelToken);
418-
}
419-
};
420-
421-
public request = async <T = any, E = any>({
422-
body,
423-
secure,
424-
path,
425-
type,
426-
query,
427-
format,
428-
baseUrl,
429-
cancelToken,
430-
...params
431-
}: FullRequestParams): Promise<HttpResponse<T, E>> => {
432-
const secureParams =
433-
((typeof secure === "boolean" ? secure : this.baseApiParams.secure) &&
434-
this.securityWorker &&
435-
(await this.securityWorker(this.securityData))) ||
436-
{};
437-
const requestParams = this.mergeRequestParams(params, secureParams);
438-
const queryString = query && this.toQueryString(query);
439-
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
440-
const responseFormat = format || requestParams.format;
441-
442-
return this.customFetch(\`\${baseUrl || this.baseUrl || ""}\${path}\${queryString ? \`?\${queryString}\` : ""}\`, {
443-
...requestParams,
444-
headers: {
445-
...(requestParams.headers || {}),
446-
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}),
447-
},
448-
signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null,
449-
body: typeof body === "undefined" || body === null ? null : payloadFormatter(body),
450-
}).then(async (response) => {
451-
const r = response.clone() as HttpResponse<T, E>;
452-
r.data = null as unknown as T;
453-
r.error = null as unknown as E;
454-
455-
const data = !responseFormat
456-
? r
457-
: await response[responseFormat]()
458-
.then((data) => {
459-
if (r.ok) {
460-
r.data = data;
461-
} else {
462-
r.error = data;
463-
}
464-
return r;
465-
})
466-
.catch((e) => {
467-
r.error = e;
468-
return r;
469-
});
470-
471-
if (cancelToken) {
472-
this.abortControllers.delete(cancelToken);
473-
}
474-
475-
if (!response.ok) throw data;
476-
return data;
477-
});
478-
};
479-
}
480-
481-
/**
482-
* @title No title
483-
* @baseUrl http://localhost:8080/api/v1
484-
*/
485-
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {}
486-
"
487-
`;

0 commit comments

Comments
 (0)