Revize 7e048a58
Přidáno uživatelem Michal Schwob před téměř 3 roky(ů)
frontend/src/swagger/CatalogItems.ts | ||
---|---|---|
1 |
/* eslint-disable */ |
|
2 |
/* tslint:disable */ |
|
3 |
/* |
|
4 |
* --------------------------------------------------------------- |
|
5 |
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## |
|
6 |
* ## ## |
|
7 |
* ## AUTHOR: acacode ## |
|
8 |
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ## |
|
9 |
* --------------------------------------------------------------- |
|
10 |
*/ |
|
11 |
|
|
12 |
import { CatalogItemDto } from "./data-contracts"; |
|
13 |
import { ContentType, HttpClient, RequestParams } from "./http-client"; |
|
14 |
|
|
15 |
export class CatalogItems<SecurityDataType = unknown> extends HttpClient<SecurityDataType> { |
|
16 |
/** |
|
17 |
* No description |
|
18 |
* |
|
19 |
* @tags catalog-controller |
|
20 |
* @name GetCatalogItem |
|
21 |
* @summary returns catalog item with given ID |
|
22 |
* @request GET:/catalog-items/{id} |
|
23 |
*/ |
|
24 |
getCatalogItem = (id: string, params: RequestParams = {}) => |
|
25 |
this.request<CatalogItemDto, any>({ |
|
26 |
path: `/catalog-items/${id}`, |
|
27 |
method: "GET", |
|
28 |
format: "json", |
|
29 |
...params, |
|
30 |
}); |
|
31 |
/** |
|
32 |
* No description |
|
33 |
* |
|
34 |
* @tags catalog-controller |
|
35 |
* @name UpdateCatalogItem |
|
36 |
* @summary updates catalog item with given ID |
|
37 |
* @request PUT:/catalog-items/{id} |
|
38 |
*/ |
|
39 |
updateCatalogItem = (id: string, data: CatalogItemDto, params: RequestParams = {}) => |
|
40 |
this.request<void, any>({ |
|
41 |
path: `/catalog-items/${id}`, |
|
42 |
method: "PUT", |
|
43 |
body: data, |
|
44 |
type: ContentType.Json, |
|
45 |
...params, |
|
46 |
}); |
|
47 |
/** |
|
48 |
* No description |
|
49 |
* |
|
50 |
* @tags catalog-controller |
|
51 |
* @name DeleteCatalogItem |
|
52 |
* @summary deletes catalog item with given ID |
|
53 |
* @request DELETE:/catalog-items/{id} |
|
54 |
*/ |
|
55 |
deleteCatalogItem = (id: string, params: RequestParams = {}) => |
|
56 |
this.request<void, any>({ |
|
57 |
path: `/catalog-items/${id}`, |
|
58 |
method: "DELETE", |
|
59 |
...params, |
|
60 |
}); |
|
61 |
/** |
|
62 |
* No description |
|
63 |
* |
|
64 |
* @tags catalog-controller |
|
65 |
* @name GetCatalog |
|
66 |
* @summary returns catalog items based on filter |
|
67 |
* @request GET:/catalog-items |
|
68 |
*/ |
|
69 |
getCatalog = (query?: { name?: string; country?: string; type?: string }, params: RequestParams = {}) => |
|
70 |
this.request<CatalogItemDto[], any>({ |
|
71 |
path: `/catalog-items`, |
|
72 |
method: "GET", |
|
73 |
query: query, |
|
74 |
...params, |
|
75 |
}); |
|
76 |
/** |
|
77 |
* No description |
|
78 |
* |
|
79 |
* @tags catalog-controller |
|
80 |
* @name AddCatalogItem |
|
81 |
* @summary creates new catalog item |
|
82 |
* @request POST:/catalog-items |
|
83 |
*/ |
|
84 |
addCatalogItem = (data: CatalogItemDto, params: RequestParams = {}) => |
|
85 |
this.request<void, any>({ |
|
86 |
path: `/catalog-items`, |
|
87 |
method: "POST", |
|
88 |
body: data, |
|
89 |
type: ContentType.Json, |
|
90 |
...params, |
|
91 |
}); |
|
92 |
} |
frontend/src/swagger/TitlePage.ts | ||
---|---|---|
1 |
/* eslint-disable */ |
|
2 |
/* tslint:disable */ |
|
3 |
/* |
|
4 |
* --------------------------------------------------------------- |
|
5 |
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## |
|
6 |
* ## ## |
|
7 |
* ## AUTHOR: acacode ## |
|
8 |
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ## |
|
9 |
* --------------------------------------------------------------- |
|
10 |
*/ |
|
11 |
|
|
12 |
import { TitlePageDto } from "./data-contracts"; |
|
13 |
import { ContentType, HttpClient, RequestParams } from "./http-client"; |
|
14 |
|
|
15 |
export class TitlePage<SecurityDataType = unknown> extends HttpClient<SecurityDataType> { |
|
16 |
/** |
|
17 |
* No description |
|
18 |
* |
|
19 |
* @tags title-page-controller |
|
20 |
* @name GetTitlePage |
|
21 |
* @summary returns title page |
|
22 |
* @request GET:/title-page |
|
23 |
*/ |
|
24 |
getTitlePage = (params: RequestParams = {}) => |
|
25 |
this.request<TitlePageDto, any>({ |
|
26 |
path: `/title-page`, |
|
27 |
method: "GET", |
|
28 |
...params, |
|
29 |
}); |
|
30 |
/** |
|
31 |
* No description |
|
32 |
* |
|
33 |
* @tags title-page-controller |
|
34 |
* @name UpdateTitlePage |
|
35 |
* @summary updates/creates title page |
|
36 |
* @request POST:/title-page |
|
37 |
*/ |
|
38 |
updateTitlePage = (data: TitlePageDto, params: RequestParams = {}) => |
|
39 |
this.request<void, any>({ |
|
40 |
path: `/title-page`, |
|
41 |
method: "POST", |
|
42 |
body: data, |
|
43 |
type: ContentType.Json, |
|
44 |
...params, |
|
45 |
}); |
|
46 |
} |
frontend/src/swagger/Users.ts | ||
---|---|---|
1 |
/* eslint-disable */ |
|
2 |
/* tslint:disable */ |
|
3 |
/* |
|
4 |
* --------------------------------------------------------------- |
|
5 |
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## |
|
6 |
* ## ## |
|
7 |
* ## AUTHOR: acacode ## |
|
8 |
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ## |
|
9 |
* --------------------------------------------------------------- |
|
10 |
*/ |
|
11 |
|
|
12 |
import { PasswordDto, PermissionDto, UserDto } from "./data-contracts"; |
|
13 |
import { ContentType, HttpClient, RequestParams } from "./http-client"; |
|
14 |
|
|
15 |
export class Users<SecurityDataType = unknown> extends HttpClient<SecurityDataType> { |
|
16 |
/** |
|
17 |
* No description |
|
18 |
* |
|
19 |
* @tags user-controller |
|
20 |
* @name GetAllUsers |
|
21 |
* @summary returns all users |
|
22 |
* @request GET:/users |
|
23 |
*/ |
|
24 |
getAllUsers = (params: RequestParams = {}) => |
|
25 |
this.request<UserDto[], any>({ |
|
26 |
path: `/users`, |
|
27 |
method: "GET", |
|
28 |
...params, |
|
29 |
}); |
|
30 |
/** |
|
31 |
* No description |
|
32 |
* |
|
33 |
* @tags user-controller |
|
34 |
* @name RegisterNewUser |
|
35 |
* @summary registers new user |
|
36 |
* @request POST:/users |
|
37 |
*/ |
|
38 |
registerNewUser = (data: UserDto, params: RequestParams = {}) => |
|
39 |
this.request<void, any>({ |
|
40 |
path: `/users`, |
|
41 |
method: "POST", |
|
42 |
body: data, |
|
43 |
type: ContentType.Json, |
|
44 |
...params, |
|
45 |
}); |
|
46 |
/** |
|
47 |
* No description |
|
48 |
* |
|
49 |
* @tags user-controller |
|
50 |
* @name UpdatePermissions |
|
51 |
* @summary changes permissions to given user |
|
52 |
* @request PATCH:/users/{username}/permissions |
|
53 |
*/ |
|
54 |
updatePermissions = (username: string, data: PermissionDto, params: RequestParams = {}) => |
|
55 |
this.request<void, any>({ |
|
56 |
path: `/users/${username}/permissions`, |
|
57 |
method: "PATCH", |
|
58 |
body: data, |
|
59 |
type: ContentType.Json, |
|
60 |
...params, |
|
61 |
}); |
|
62 |
/** |
|
63 |
* No description |
|
64 |
* |
|
65 |
* @tags user-controller |
|
66 |
* @name ResetPassword |
|
67 |
* @summary changes password to given user |
|
68 |
* @request PATCH:/users/{username}/password |
|
69 |
*/ |
|
70 |
resetPassword = (username: string, data: PasswordDto, params: RequestParams = {}) => |
|
71 |
this.request<void, any>({ |
|
72 |
path: `/users/${username}/password`, |
|
73 |
method: "PATCH", |
|
74 |
body: data, |
|
75 |
type: ContentType.Json, |
|
76 |
...params, |
|
77 |
}); |
|
78 |
/** |
|
79 |
* No description |
|
80 |
* |
|
81 |
* @tags user-controller |
|
82 |
* @name ChangePassword |
|
83 |
* @summary changes password to logged-in user |
|
84 |
* @request PATCH:/users/password |
|
85 |
*/ |
|
86 |
changePassword = (query: { oldPassword: string }, data: PasswordDto, params: RequestParams = {}) => |
|
87 |
this.request<void, any>({ |
|
88 |
path: `/users/password`, |
|
89 |
method: "PATCH", |
|
90 |
query: query, |
|
91 |
body: data, |
|
92 |
type: ContentType.Json, |
|
93 |
...params, |
|
94 |
}); |
|
95 |
/** |
|
96 |
* No description |
|
97 |
* |
|
98 |
* @tags user-controller |
|
99 |
* @name RefreshToken |
|
100 |
* @summary returns a new access token and a refresh token to user |
|
101 |
* @request GET:/users/token |
|
102 |
*/ |
|
103 |
refreshToken = (params: RequestParams = {}) => |
|
104 |
this.request<void, any>({ |
|
105 |
path: `/users/token`, |
|
106 |
method: "GET", |
|
107 |
...params, |
|
108 |
}); |
|
109 |
/** |
|
110 |
* No description |
|
111 |
* |
|
112 |
* @tags user-controller |
|
113 |
* @name DeleteUser |
|
114 |
* @summary deletes user with given username |
|
115 |
* @request DELETE:/users/{username} |
|
116 |
*/ |
|
117 |
deleteUser = (username: string, params: RequestParams = {}) => |
|
118 |
this.request<void, any>({ |
|
119 |
path: `/users/${username}`, |
|
120 |
method: "DELETE", |
|
121 |
...params, |
|
122 |
}); |
|
123 |
} |
frontend/src/swagger/data-contracts.ts | ||
---|---|---|
1 |
/* eslint-disable */ |
|
2 |
/* tslint:disable */ |
|
3 |
/* |
|
4 |
* --------------------------------------------------------------- |
|
5 |
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## |
|
6 |
* ## ## |
|
7 |
* ## AUTHOR: acacode ## |
|
8 |
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ## |
|
9 |
* --------------------------------------------------------------- |
|
10 |
*/ |
|
11 |
|
|
12 |
export interface CatalogItemDto { |
|
13 |
/** @format uuid */ |
|
14 |
id?: string; |
|
15 |
name?: string; |
|
16 |
|
|
17 |
/** @format int32 */ |
|
18 |
certainty?: number; |
|
19 |
|
|
20 |
/** @format double */ |
|
21 |
longitude?: number; |
|
22 |
|
|
23 |
/** @format double */ |
|
24 |
latitude?: number; |
|
25 |
bibliography?: string[]; |
|
26 |
countries?: string[]; |
|
27 |
writtenForms?: string[]; |
|
28 |
alternativeNames?: string[]; |
|
29 |
types?: string[]; |
|
30 |
} |
|
31 |
|
|
32 |
export interface PasswordDto { |
|
33 |
password: string; |
|
34 |
confirmationPassword: string; |
|
35 |
} |
|
36 |
|
|
37 |
export interface PermissionDto { |
|
38 |
canRead?: boolean; |
|
39 |
canWrite?: boolean; |
|
40 |
canDelete?: boolean; |
|
41 |
} |
|
42 |
|
|
43 |
export interface UserDto { |
|
44 |
name?: string; |
|
45 |
email: string; |
|
46 |
permissions?: PermissionDto; |
|
47 |
passwords: PasswordDto; |
|
48 |
} |
|
49 |
|
|
50 |
export interface TitlePageDto { |
|
51 |
title?: string; |
|
52 |
content?: string; |
|
53 |
} |
frontend/src/swagger/http-client.ts | ||
---|---|---|
1 |
/* eslint-disable */ |
|
2 |
/* tslint:disable */ |
|
3 |
/* |
|
4 |
* --------------------------------------------------------------- |
|
5 |
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ## |
|
6 |
* ## ## |
|
7 |
* ## AUTHOR: acacode ## |
|
8 |
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ## |
|
9 |
* --------------------------------------------------------------- |
|
10 |
*/ |
|
11 |
|
|
12 |
export type QueryParamsType = Record<string | number, any>; |
|
13 |
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">; |
|
14 |
|
|
15 |
export interface FullRequestParams extends Omit<RequestInit, "body"> { |
|
16 |
/** set parameter to `true` for call `securityWorker` for this request */ |
|
17 |
secure?: boolean; |
|
18 |
/** request path */ |
|
19 |
path: string; |
|
20 |
/** content type of request body */ |
|
21 |
type?: ContentType; |
|
22 |
/** query params */ |
|
23 |
query?: QueryParamsType; |
|
24 |
/** format of response (i.e. response.json() -> format: "json") */ |
|
25 |
format?: ResponseFormat; |
|
26 |
/** request body */ |
|
27 |
body?: unknown; |
|
28 |
/** base url */ |
|
29 |
baseUrl?: string; |
|
30 |
/** request cancellation token */ |
|
31 |
cancelToken?: CancelToken; |
|
32 |
} |
|
33 |
|
|
34 |
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">; |
|
35 |
|
|
36 |
export interface ApiConfig<SecurityDataType = unknown> { |
|
37 |
baseUrl?: string; |
|
38 |
baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">; |
|
39 |
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void; |
|
40 |
customFetch?: typeof fetch; |
|
41 |
} |
|
42 |
|
|
43 |
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response { |
|
44 |
data: D; |
|
45 |
error: E; |
|
46 |
} |
|
47 |
|
|
48 |
type CancelToken = Symbol | string | number; |
|
49 |
|
|
50 |
export enum ContentType { |
|
51 |
Json = "application/json", |
|
52 |
FormData = "multipart/form-data", |
|
53 |
UrlEncoded = "application/x-www-form-urlencoded", |
|
54 |
} |
|
55 |
|
|
56 |
export class HttpClient<SecurityDataType = unknown> { |
|
57 |
public baseUrl: string = "http://147.228.110.32:8080"; |
|
58 |
private securityData: SecurityDataType | null = null; |
|
59 |
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"]; |
|
60 |
private abortControllers = new Map<CancelToken, AbortController>(); |
|
61 |
private customFetch = (...fetchParams: Parameters<typeof fetch>) => fetch(...fetchParams); |
|
62 |
|
|
63 |
private baseApiParams: RequestParams = { |
|
64 |
credentials: "same-origin", |
|
65 |
headers: {}, |
|
66 |
redirect: "follow", |
|
67 |
referrerPolicy: "no-referrer", |
|
68 |
}; |
|
69 |
|
|
70 |
constructor(apiConfig: ApiConfig<SecurityDataType> = {}) { |
|
71 |
Object.assign(this, apiConfig); |
|
72 |
} |
|
73 |
|
|
74 |
public setSecurityData = (data: SecurityDataType | null) => { |
|
75 |
this.securityData = data; |
|
76 |
}; |
|
77 |
|
|
78 |
private encodeQueryParam(key: string, value: any) { |
|
79 |
const encodedKey = encodeURIComponent(key); |
|
80 |
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`; |
|
81 |
} |
|
82 |
|
|
83 |
private addQueryParam(query: QueryParamsType, key: string) { |
|
84 |
return this.encodeQueryParam(key, query[key]); |
|
85 |
} |
|
86 |
|
|
87 |
private addArrayQueryParam(query: QueryParamsType, key: string) { |
|
88 |
const value = query[key]; |
|
89 |
return value.map((v: any) => this.encodeQueryParam(key, v)).join("&"); |
|
90 |
} |
|
91 |
|
|
92 |
protected toQueryString(rawQuery?: QueryParamsType): string { |
|
93 |
const query = rawQuery || {}; |
|
94 |
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]); |
|
95 |
return keys |
|
96 |
.map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key))) |
|
97 |
.join("&"); |
|
98 |
} |
|
99 |
|
|
100 |
protected addQueryParams(rawQuery?: QueryParamsType): string { |
|
101 |
const queryString = this.toQueryString(rawQuery); |
|
102 |
return queryString ? `?${queryString}` : ""; |
|
103 |
} |
|
104 |
|
|
105 |
private contentFormatters: Record<ContentType, (input: any) => any> = { |
|
106 |
[ContentType.Json]: (input: any) => |
|
107 |
input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input, |
|
108 |
[ContentType.FormData]: (input: any) => |
|
109 |
Object.keys(input || {}).reduce((formData, key) => { |
|
110 |
const property = input[key]; |
|
111 |
formData.append( |
|
112 |
key, |
|
113 |
property instanceof Blob |
|
114 |
? property |
|
115 |
: typeof property === "object" && property !== null |
|
116 |
? JSON.stringify(property) |
|
117 |
: `${property}`, |
|
118 |
); |
|
119 |
return formData; |
|
120 |
}, new FormData()), |
|
121 |
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input), |
|
122 |
}; |
|
123 |
|
|
124 |
private mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams { |
|
125 |
return { |
|
126 |
...this.baseApiParams, |
|
127 |
...params1, |
|
128 |
...(params2 || {}), |
|
129 |
headers: { |
|
130 |
...(this.baseApiParams.headers || {}), |
|
131 |
...(params1.headers || {}), |
|
132 |
...((params2 && params2.headers) || {}), |
|
133 |
}, |
|
134 |
}; |
|
135 |
} |
|
136 |
|
|
137 |
private createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => { |
|
138 |
if (this.abortControllers.has(cancelToken)) { |
|
139 |
const abortController = this.abortControllers.get(cancelToken); |
|
140 |
if (abortController) { |
|
141 |
return abortController.signal; |
|
142 |
} |
|
143 |
return void 0; |
|
144 |
} |
|
145 |
|
|
146 |
const abortController = new AbortController(); |
|
147 |
this.abortControllers.set(cancelToken, abortController); |
|
148 |
return abortController.signal; |
|
149 |
}; |
|
150 |
|
|
151 |
public abortRequest = (cancelToken: CancelToken) => { |
|
152 |
const abortController = this.abortControllers.get(cancelToken); |
|
153 |
|
|
154 |
if (abortController) { |
|
155 |
abortController.abort(); |
|
156 |
this.abortControllers.delete(cancelToken); |
|
157 |
} |
|
158 |
}; |
|
159 |
|
|
160 |
public request = async <T = any, E = any>({ |
|
161 |
body, |
|
162 |
secure, |
|
163 |
path, |
|
164 |
type, |
|
165 |
query, |
|
166 |
format, |
|
167 |
baseUrl, |
|
168 |
cancelToken, |
|
169 |
...params |
|
170 |
}: FullRequestParams): Promise<HttpResponse<T, E>> => { |
|
171 |
const secureParams = |
|
172 |
((typeof secure === "boolean" ? secure : this.baseApiParams.secure) && |
|
173 |
this.securityWorker && |
|
174 |
(await this.securityWorker(this.securityData))) || |
|
175 |
{}; |
|
176 |
const requestParams = this.mergeRequestParams(params, secureParams); |
|
177 |
const queryString = query && this.toQueryString(query); |
|
178 |
const payloadFormatter = this.contentFormatters[type || ContentType.Json]; |
|
179 |
const responseFormat = format || requestParams.format; |
|
180 |
|
|
181 |
return this.customFetch(`${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`, { |
|
182 |
...requestParams, |
|
183 |
headers: { |
|
184 |
...(type && type !== ContentType.FormData ? { "Content-Type": type } : {}), |
|
185 |
...(requestParams.headers || {}), |
|
186 |
}, |
|
187 |
signal: cancelToken ? this.createAbortSignal(cancelToken) : void 0, |
|
188 |
body: typeof body === "undefined" || body === null ? null : payloadFormatter(body), |
|
189 |
}).then(async (response) => { |
|
190 |
const r = response as HttpResponse<T, E>; |
|
191 |
r.data = null as unknown as T; |
|
192 |
r.error = null as unknown as E; |
|
193 |
|
|
194 |
const data = !responseFormat |
|
195 |
? r |
|
196 |
: await response[responseFormat]() |
|
197 |
.then((data) => { |
|
198 |
if (r.ok) { |
|
199 |
r.data = data; |
|
200 |
} else { |
|
201 |
r.error = data; |
|
202 |
} |
|
203 |
return r; |
|
204 |
}) |
|
205 |
.catch((e) => { |
|
206 |
r.error = e; |
|
207 |
return r; |
|
208 |
}); |
|
209 |
|
|
210 |
if (cancelToken) { |
|
211 |
this.abortControllers.delete(cancelToken); |
|
212 |
} |
|
213 |
|
|
214 |
if (!response.ok) throw data; |
|
215 |
return data; |
|
216 |
}); |
|
217 |
}; |
|
218 |
} |
Také k dispozici: Unified diff
Swagger generated files
re #9333