forked from orval-labs/orval
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpets.ts
More file actions
198 lines (173 loc) 路 4.49 KB
/
Copy pathpets.ts
File metadata and controls
198 lines (173 loc) 路 4.49 KB
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
/**
* Generated by orval v8.11.0 馃嵑
* Do not edit manually.
* Swagger Petstore
* OpenAPI spec version: 1.0.0
*/
import type {
CountryCode,
Error,
ListPetsByAgeParams,
ListPetsByCountryParams,
Pets,
} from '../model';
export type HTTPStatusCode1xx = 100 | 101 | 102 | 103;
export type HTTPStatusCode2xx = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207;
export type HTTPStatusCode3xx = 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308;
export type HTTPStatusCode4xx =
| 400
| 401
| 402
| 403
| 404
| 405
| 406
| 407
| 408
| 409
| 410
| 411
| 412
| 413
| 414
| 415
| 416
| 417
| 418
| 419
| 420
| 421
| 422
| 423
| 424
| 426
| 428
| 429
| 431
| 451;
export type HTTPStatusCode5xx = 500 | 501 | 502 | 503 | 504 | 505 | 507 | 511;
export type HTTPStatusCodes =
| HTTPStatusCode1xx
| HTTPStatusCode2xx
| HTTPStatusCode3xx
| HTTPStatusCode4xx
| HTTPStatusCode5xx;
export type listPetsByCountryResponse200 = {
data: Pets;
status: 200;
};
export type listPetsByCountryResponseDefault = {
data: Error;
status: Exclude<HTTPStatusCodes, 200>;
};
export type listPetsByCountryResponseSuccess = listPetsByCountryResponse200 & {
headers: Headers;
};
export type listPetsByCountryResponseError =
listPetsByCountryResponseDefault & {
headers: Headers;
};
export type listPetsByCountryResponse =
| listPetsByCountryResponseSuccess
| listPetsByCountryResponseError;
export const getListPetsByCountryUrl = (
params?: ListPetsByCountryParams,
country: CountryCode = 'UY',
) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
const explodeParameters = ['tag'];
if (Array.isArray(value) && explodeParameters.includes(key)) {
value.forEach((v) => {
normalizedParams.append(key, v === null ? 'null' : String(v));
});
return;
}
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : String(value));
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/pets-by-country/${encodeURIComponent(String(country))}?${stringifiedParams}`
: `/pets-by-country/${encodeURIComponent(String(country))}`;
};
/**
* @summary List all pets by country
*/
export const listPetsByCountry = async (
params?: ListPetsByCountryParams,
country: CountryCode = 'UY',
options?: RequestInit,
): Promise<listPetsByCountryResponse> => {
const res = await fetch(getListPetsByCountryUrl(params, country), {
...options,
method: 'GET',
});
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: listPetsByCountryResponse['data'] = body ? JSON.parse(body) : {};
return {
data,
status: res.status,
headers: res.headers,
} as listPetsByCountryResponse;
};
export type listPetsByAgeResponse200 = {
data: Pets;
status: 200;
};
export type listPetsByAgeResponseDefault = {
data: Error;
status: Exclude<HTTPStatusCodes, 200>;
};
export type listPetsByAgeResponseSuccess = listPetsByAgeResponse200 & {
headers: Headers;
};
export type listPetsByAgeResponseError = listPetsByAgeResponseDefault & {
headers: Headers;
};
export type listPetsByAgeResponse =
| listPetsByAgeResponseSuccess
| listPetsByAgeResponseError;
export const getListPetsByAgeUrl = (
params?: ListPetsByAgeParams,
age: number = 5,
) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(
key,
value === null
? 'null'
: value instanceof Date
? value.toISOString()
: String(value),
);
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0
? `/pets-by-age/${encodeURIComponent(String(age))}?${stringifiedParams}`
: `/pets-by-age/${encodeURIComponent(String(age))}`;
};
/**
* @summary List all pets by age
*/
export const listPetsByAge = async (
params?: ListPetsByAgeParams,
age: number = 5,
options?: RequestInit,
): Promise<listPetsByAgeResponse> => {
const res = await fetch(getListPetsByAgeUrl(params, age), {
...options,
method: 'GET',
});
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: listPetsByAgeResponse['data'] = body ? JSON.parse(body) : {};
return {
data,
status: res.status,
headers: res.headers,
} as listPetsByAgeResponse;
};