Skip to content

Commit 6883a26

Browse files
committed
chore: update examples output
1 parent 91378ee commit 6883a26

File tree

5 files changed

+208
-113
lines changed

5 files changed

+208
-113
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ const Pet = z.object({ id: z.number().int(), name: z.string(), tag: z.string().o
216216
const Pets = z.array(Pet);
217217
const Error = z.object({ code: z.number().int(), message: z.string() });
218218
219-
const variables = {};
220-
221219
const endpoints = makeApi([
222220
{
223221
method: "get",

example/petstore-client.ts

Lines changed: 175 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,42 @@
11
import { makeApi, Zodios } from "@zodios/core";
22
import { z } from "zod";
33

4-
const vR1x0k5qaLk = z.object({ id: z.number(), name: z.string() }).partial();
5-
const v8JbFEq2fUl = z.object({
6-
id: z.number().optional(),
4+
const Category = z.object({ id: z.number().int(), name: z.string() }).partial();
5+
const Tag = z.object({ id: z.number().int(), name: z.string() }).partial();
6+
const Pet = z.object({
7+
id: z.number().int().optional(),
78
name: z.string(),
8-
category: vR1x0k5qaLk.optional(),
9+
category: Category.optional(),
910
photoUrls: z.array(z.string()),
10-
tags: z.array(vR1x0k5qaLk).optional(),
11+
tags: z.array(Tag).optional(),
1112
status: z.enum(["available", "pending", "sold"]).optional(),
1213
});
13-
const vlh4E1pXYTG = z.enum(["available", "pending", "sold"]).optional();
14-
const vh4fxCvnN1b = z.array(v8JbFEq2fUl);
15-
const vGqL1kemtHF = z.array(z.string()).optional();
16-
const vBaxCoPHbgy = z.object({ code: z.number(), type: z.string(), message: z.string() }).partial();
17-
const vLBYC40hXo1 = z
14+
const status = z.enum(["available", "pending", "sold"]).optional();
15+
const tags = z.array(z.string()).optional();
16+
const ApiResponse = z.object({ code: z.number().int(), type: z.string(), message: z.string() }).partial();
17+
const Order = z
1818
.object({
19-
id: z.number(),
20-
petId: z.number(),
21-
quantity: z.number(),
19+
id: z.number().int(),
20+
petId: z.number().int(),
21+
quantity: z.number().int(),
2222
shipDate: z.string(),
2323
status: z.enum(["placed", "approved", "delivered"]),
2424
complete: z.boolean(),
2525
})
2626
.partial();
27-
const veNKKR5W6KW = z
27+
const User = z
2828
.object({
29-
id: z.number(),
29+
id: z.number().int(),
3030
username: z.string(),
3131
firstName: z.string(),
3232
lastName: z.string(),
3333
email: z.string(),
3434
password: z.string(),
3535
phone: z.string(),
36-
userStatus: z.number(),
36+
userStatus: z.number().int(),
3737
})
3838
.partial();
39-
const vVrSPZVa6q7 = z.array(veNKKR5W6KW);
40-
41-
const variables = {
42-
ApiResponse: vBaxCoPHbgy,
43-
Order: vLBYC40hXo1,
44-
Pet: v8JbFEq2fUl,
45-
User: veNKKR5W6KW,
46-
addPet: v8JbFEq2fUl,
47-
addPet_Body: v8JbFEq2fUl,
48-
createUser: veNKKR5W6KW,
49-
createUser_Body: veNKKR5W6KW,
50-
createUsersWithListInput: veNKKR5W6KW,
51-
createUsersWithListInput_Body: vVrSPZVa6q7,
52-
findPetsByStatus: vh4fxCvnN1b,
53-
findPetsByTags: vh4fxCvnN1b,
54-
getOrderById: vLBYC40hXo1,
55-
getPetById: v8JbFEq2fUl,
56-
getUserByName: veNKKR5W6KW,
57-
placeOrder: vLBYC40hXo1,
58-
placeOrder_Body: vLBYC40hXo1,
59-
status: vlh4E1pXYTG,
60-
tags: vGqL1kemtHF,
61-
updatePet: v8JbFEq2fUl,
62-
updatePet_Body: v8JbFEq2fUl,
63-
updateUser_Body: veNKKR5W6KW,
64-
uploadFile: vBaxCoPHbgy,
65-
};
39+
const createUsersWithListInput_Body = z.array(User);
6640

6741
const endpoints = makeApi([
6842
{
@@ -75,10 +49,27 @@ const endpoints = makeApi([
7549
name: "body",
7650
description: `Update an existent pet in the store`,
7751
type: "Body",
78-
schema: variables["updatePet_Body"],
52+
schema: Pet,
53+
},
54+
],
55+
response: Pet,
56+
errors: [
57+
{
58+
status: 400,
59+
description: `Invalid ID supplied`,
60+
schema: z.void(),
61+
},
62+
{
63+
status: 404,
64+
description: `Pet not found`,
65+
schema: z.void(),
66+
},
67+
{
68+
status: 405,
69+
description: `Validation exception`,
70+
schema: z.void(),
7971
},
8072
],
81-
response: variables["Pet"],
8273
},
8374
{
8475
method: "post",
@@ -90,30 +81,61 @@ const endpoints = makeApi([
9081
name: "body",
9182
description: `Create a new pet in the store`,
9283
type: "Body",
93-
schema: variables["addPet_Body"],
84+
schema: Pet,
85+
},
86+
],
87+
response: Pet,
88+
errors: [
89+
{
90+
status: 405,
91+
description: `Invalid input`,
92+
schema: z.void(),
9493
},
9594
],
96-
response: variables["Pet"],
9795
},
9896
{
9997
method: "get",
10098
path: "/pet/:petId",
10199
description: `Returns a single pet`,
102100
requestFormat: "json",
103-
response: variables["Pet"],
101+
parameters: [
102+
{
103+
name: "petId",
104+
type: "Path",
105+
schema: z.number(),
106+
},
107+
],
108+
response: Pet,
109+
errors: [
110+
{
111+
status: 400,
112+
description: `Invalid ID supplied`,
113+
schema: z.void(),
114+
},
115+
{
116+
status: 404,
117+
description: `Pet not found`,
118+
schema: z.void(),
119+
},
120+
],
104121
},
105122
{
106123
method: "post",
107124
path: "/pet/:petId/uploadImage",
108125
requestFormat: "json",
109126
parameters: [
127+
{
128+
name: "petId",
129+
type: "Path",
130+
schema: z.number(),
131+
},
110132
{
111133
name: "additionalMetadata",
112134
type: "Query",
113135
schema: z.string().optional(),
114136
},
115137
],
116-
response: variables["ApiResponse"],
138+
response: ApiResponse,
117139
},
118140
{
119141
method: "get",
@@ -124,10 +146,17 @@ const endpoints = makeApi([
124146
{
125147
name: "status",
126148
type: "Query",
127-
schema: variables["status"],
149+
schema: status,
150+
},
151+
],
152+
response: z.array(Pet),
153+
errors: [
154+
{
155+
status: 400,
156+
description: `Invalid status value`,
157+
schema: z.void(),
128158
},
129159
],
130-
response: z.array(variables["getPetById"]),
131160
},
132161
{
133162
method: "get",
@@ -138,10 +167,17 @@ const endpoints = makeApi([
138167
{
139168
name: "tags",
140169
type: "Query",
141-
schema: variables["tags"],
170+
schema: tags,
171+
},
172+
],
173+
response: z.array(Pet),
174+
errors: [
175+
{
176+
status: 400,
177+
description: `Invalid tag value`,
178+
schema: z.void(),
142179
},
143180
],
144-
response: z.array(variables["getPetById"]),
145181
},
146182
{
147183
method: "get",
@@ -159,17 +195,43 @@ const endpoints = makeApi([
159195
{
160196
name: "body",
161197
type: "Body",
162-
schema: variables["placeOrder_Body"],
198+
schema: Order,
199+
},
200+
],
201+
response: Order,
202+
errors: [
203+
{
204+
status: 405,
205+
description: `Invalid input`,
206+
schema: z.void(),
163207
},
164208
],
165-
response: variables["Order"],
166209
},
167210
{
168211
method: "get",
169212
path: "/store/order/:orderId",
170213
description: `For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.`,
171214
requestFormat: "json",
172-
response: variables["Order"],
215+
parameters: [
216+
{
217+
name: "orderId",
218+
type: "Path",
219+
schema: z.number(),
220+
},
221+
],
222+
response: Order,
223+
errors: [
224+
{
225+
status: 400,
226+
description: `Invalid ID supplied`,
227+
schema: z.void(),
228+
},
229+
{
230+
status: 404,
231+
description: `Order not found`,
232+
schema: z.void(),
233+
},
234+
],
173235
},
174236
{
175237
method: "post",
@@ -181,16 +243,55 @@ const endpoints = makeApi([
181243
name: "body",
182244
description: `Created user object`,
183245
type: "Body",
184-
schema: variables["createUser_Body"],
246+
schema: User,
185247
},
186248
],
187-
response: variables["User"],
249+
response: User,
188250
},
189251
{
190252
method: "get",
191253
path: "/user/:username",
192254
requestFormat: "json",
193-
response: variables["User"],
255+
parameters: [
256+
{
257+
name: "username",
258+
type: "Path",
259+
schema: z.string(),
260+
},
261+
],
262+
response: User,
263+
errors: [
264+
{
265+
status: 400,
266+
description: `Invalid username supplied`,
267+
schema: z.void(),
268+
},
269+
{
270+
status: 404,
271+
description: `User not found`,
272+
schema: z.void(),
273+
},
274+
],
275+
},
276+
{
277+
method: "put",
278+
path: "/user/:username",
279+
description: `This can only be done by the logged in user.`,
280+
requestFormat: "json",
281+
parameters: [
282+
{
283+
name: "body",
284+
description: `Update an existent user in the store`,
285+
type: "Body",
286+
schema: User,
287+
},
288+
{
289+
name: "username",
290+
type: "Path",
291+
schema: z.string(),
292+
},
293+
],
294+
response: z.void(),
194295
},
195296
{
196297
method: "post",
@@ -201,10 +302,10 @@ const endpoints = makeApi([
201302
{
202303
name: "body",
203304
type: "Body",
204-
schema: variables["createUsersWithListInput_Body"],
305+
schema: createUsersWithListInput_Body,
205306
},
206307
],
207-
response: variables["User"],
308+
response: User,
208309
},
209310
{
210311
method: "get",
@@ -223,6 +324,19 @@ const endpoints = makeApi([
223324
},
224325
],
225326
response: z.string(),
327+
errors: [
328+
{
329+
status: 400,
330+
description: `Invalid username/password supplied`,
331+
schema: z.void(),
332+
},
333+
],
334+
},
335+
{
336+
method: "get",
337+
path: "/user/logout",
338+
requestFormat: "json",
339+
response: z.void(),
226340
},
227341
]);
228342

0 commit comments

Comments
 (0)