chore(ui): regenerate api

This commit is contained in:
psychedelicious 2023-04-04 18:30:52 +10:00
parent de0df4945d
commit b7de3162c3
7 changed files with 169 additions and 22 deletions

View File

@ -4,9 +4,9 @@
/**
* Custom `request.ts` file for OpenAPI code generator.
*
*
* Patches the request logic in such a way that we can extract headers from requests.
*
*
* Copied from https://github.com/ferdikoomen/openapi-typescript-codegen/issues/829#issuecomment-1228224477
*/
@ -21,9 +21,11 @@ import { CancelablePromise } from './CancelablePromise';
import type { OnCancel } from './CancelablePromise';
import type { OpenAPIConfig } from './OpenAPI';
export const HEADERS = Symbol("HEADERS")
export const HEADERS = Symbol('HEADERS');
const isDefined = <T>(value: T | null | undefined): value is Exclude<T, null | undefined> => {
const isDefined = <T>(
value: T | null | undefined
): value is Exclude<T, null | undefined> => {
return value !== undefined && value !== null;
};
@ -75,7 +77,7 @@ const getQueryString = (params: Record<string, any>): string => {
const process = (key: string, value: any) => {
if (isDefined(value)) {
if (Array.isArray(value)) {
value.forEach(v => {
value.forEach((v) => {
process(key, v);
});
} else if (typeof value === 'object') {
@ -134,7 +136,7 @@ const getFormData = (options: ApiRequestOptions): FormData | undefined => {
.filter(([_, value]) => isDefined(value))
.forEach(([key, value]) => {
if (Array.isArray(value)) {
value.forEach(v => process(key, v));
value.forEach((v) => process(key, v));
} else {
process(key, value);
}
@ -147,19 +149,28 @@ const getFormData = (options: ApiRequestOptions): FormData | undefined => {
type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
const resolve = async <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>): Promise<T | undefined> => {
const resolve = async <T>(
options: ApiRequestOptions,
resolver?: T | Resolver<T>
): Promise<T | undefined> => {
if (typeof resolver === 'function') {
return (resolver as Resolver<T>)(options);
}
return resolver;
};
const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, formData?: FormData): Promise<Record<string, string>> => {
const getHeaders = async (
config: OpenAPIConfig,
options: ApiRequestOptions,
formData?: FormData
): Promise<Record<string, string>> => {
const token = await resolve(options, config.TOKEN);
const username = await resolve(options, config.USERNAME);
const password = await resolve(options, config.PASSWORD);
const additionalHeaders = await resolve(options, config.HEADERS);
const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders() || {}
const formHeaders =
(typeof formData?.getHeaders === 'function' && formData?.getHeaders()) ||
{};
const headers = Object.entries({
Accept: 'application/json',
@ -167,11 +178,14 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions, for
...options.headers,
...formHeaders,
})
.filter(([_, value]) => isDefined(value))
.reduce((headers, [key, value]) => ({
...headers,
[key]: String(value),
}), {} as Record<string, string>);
.filter(([_, value]) => isDefined(value))
.reduce(
(headers, [key, value]) => ({
...headers,
[key]: String(value),
}),
{} as Record<string, string>
);
if (isStringWithValue(token)) {
headers['Authorization'] = `Bearer ${token}`;
@ -237,7 +251,10 @@ const sendRequest = async <T>(
}
};
const getResponseHeader = (response: AxiosResponse<any>, responseHeader?: string): string | undefined => {
const getResponseHeader = (
response: AxiosResponse<any>,
responseHeader?: string
): string | undefined => {
if (responseHeader) {
const content = response.headers[responseHeader];
if (isString(content)) {
@ -254,7 +271,10 @@ const getResponseBody = (response: AxiosResponse<any>): any => {
return undefined;
};
const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void => {
const catchErrorCodes = (
options: ApiRequestOptions,
result: ApiResult
): void => {
const errors: Record<number, string> = {
400: 'Bad Request',
401: 'Unauthorized',
@ -264,7 +284,7 @@ const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void =>
502: 'Bad Gateway',
503: 'Service Unavailable',
...options.errors,
}
};
const error = errors[result.status];
if (error) {
@ -283,7 +303,10 @@ const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void =>
* @returns CancelablePromise<T>
* @throws ApiError
*/
export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): CancelablePromise<T> => {
export const request = <T>(
config: OpenAPIConfig,
options: ApiRequestOptions
): CancelablePromise<T> => {
return new CancelablePromise(async (resolve, reject, onCancel) => {
try {
const url = getUrl(config, options);
@ -292,9 +315,20 @@ export const request = <T>(config: OpenAPIConfig, options: ApiRequestOptions): C
const headers = await getHeaders(config, options, formData);
if (!onCancel.isCancelled) {
const response = await sendRequest<T>(config, options, url, body, formData, headers, onCancel);
const response = await sendRequest<T>(
config,
options,
url,
body,
formData,
headers,
onCancel
);
const responseBody = getResponseBody(response);
const responseHeader = getResponseHeader(response, options.responseHeader);
const responseHeader = getResponseHeader(
response,
options.responseHeader
);
const result: ApiResult = {
url,

View File

@ -32,6 +32,7 @@ export type { LoadImageInvocation } from './models/LoadImageInvocation';
export type { MaskFromAlphaInvocation } from './models/MaskFromAlphaInvocation';
export type { MaskOutput } from './models/MaskOutput';
export type { PaginatedResults_GraphExecutionState_ } from './models/PaginatedResults_GraphExecutionState_';
export type { PaginatedResults_ImageField_ } from './models/PaginatedResults_ImageField_';
export type { PasteImageInvocation } from './models/PasteImageInvocation';
export type { PromptOutput } from './models/PromptOutput';
export type { RestoreFaceInvocation } from './models/RestoreFaceInvocation';
@ -66,6 +67,7 @@ export { $LoadImageInvocation } from './schemas/$LoadImageInvocation';
export { $MaskFromAlphaInvocation } from './schemas/$MaskFromAlphaInvocation';
export { $MaskOutput } from './schemas/$MaskOutput';
export { $PaginatedResults_GraphExecutionState_ } from './schemas/$PaginatedResults_GraphExecutionState_';
export { $PaginatedResults_ImageField_ } from './schemas/$PaginatedResults_ImageField_';
export { $PasteImageInvocation } from './schemas/$PasteImageInvocation';
export { $PromptOutput } from './schemas/$PromptOutput';
export { $RestoreFaceInvocation } from './schemas/$RestoreFaceInvocation';

View File

@ -2,6 +2,8 @@
/* tslint:disable */
/* eslint-disable */
import type { ImageType } from './ImageType';
/**
* An image field used for passing image objects between invocations
*/
@ -9,7 +11,7 @@ export type ImageField = {
/**
* The type of the image
*/
image_type: string;
image_type: ImageType;
/**
* The name of the image
*/

View File

@ -0,0 +1,32 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ImageField } from './ImageField';
/**
* Paginated results
*/
export type PaginatedResults_ImageField_ = {
/**
* Items
*/
items: Array<ImageField>;
/**
* Current Page
*/
page: number;
/**
* Total number of pages
*/
pages: number;
/**
* Number of items per page
*/
per_page: number;
/**
* Total number of items in result
*/
total: number;
};

View File

@ -5,8 +5,11 @@ export const $ImageField = {
description: `An image field used for passing image objects between invocations`,
properties: {
image_type: {
type: 'string',
type: 'all-of',
description: `The type of the image`,
contains: [{
type: 'ImageType',
}],
isRequired: true,
},
image_name: {

View File

@ -0,0 +1,35 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export const $PaginatedResults_ImageField_ = {
description: `Paginated results`,
properties: {
items: {
type: 'array',
contains: {
type: 'ImageField',
},
isRequired: true,
},
page: {
type: 'number',
description: `Current Page`,
isRequired: true,
},
pages: {
type: 'number',
description: `Total number of pages`,
isRequired: true,
},
per_page: {
type: 'number',
description: `Number of items per page`,
isRequired: true,
},
total: {
type: 'number',
description: `Total number of items in result`,
isRequired: true,
},
},
} as const;

View File

@ -3,6 +3,7 @@
/* eslint-disable */
import type { Body_upload_image } from '../models/Body_upload_image';
import type { ImageType } from '../models/ImageType';
import type { PaginatedResults_ImageField_ } from '../models/PaginatedResults_ImageField_';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
@ -96,4 +97,42 @@ export class ImagesService {
});
}
/**
* List Images
* Gets a list of images
* @returns PaginatedResults_ImageField_ Successful Response
* @throws ApiError
*/
public static listImages({
imageType,
page,
perPage = 10,
}: {
/**
* The type of images to get
*/
imageType?: ImageType,
/**
* The page of images to get
*/
page?: number,
/**
* The number of images per page
*/
perPage?: number,
}): CancelablePromise<PaginatedResults_ImageField_> {
return __request(OpenAPI, {
method: 'GET',
url: '/api/v1/images/',
query: {
'image_type': imageType,
'page': page,
'per_page': perPage,
},
errors: {
422: `Validation Error`,
},
});
}
}