Skip to content

Commit 58bef1b

Browse files
authored
Merge pull request #38 from dev-five-git/add-null
Add nullable
2 parents 4737827 + ace033e commit 58bef1b

File tree

3 files changed

+249
-230
lines changed

3 files changed

+249
-230
lines changed

packages/generator/src/__tests__/__snapshots__/generate-interface.test.ts.snap

Lines changed: 39 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -28,102 +28,6 @@ exports[`generateInterface returns interface for schema: %s 2`] = `
2828
"import "@devup-api/fetch";
2929
import type { DevupObject } from "@devup-api/fetch";
3030

31-
declare module "@devup-api/fetch" {
32-
interface DevupApiServers {
33-
[\`openapi.json\`]: never
34-
}
35-
36-
interface DevupGetApiStruct {
37-
[\`openapi.json\`]: {
38-
[\`/users\`]: {};
39-
GetUsers: {};
40-
}
41-
}
42-
43-
interface DevupRequestComponentStruct {}
44-
45-
interface DevupResponseComponentStruct {}
46-
47-
interface DevupErrorComponentStruct {}
48-
}"
49-
`;
50-
51-
exports[`generateInterface returns interface for schema: %s 3`] = `
52-
"import "@devup-api/fetch";
53-
import type { DevupObject } from "@devup-api/fetch";
54-
55-
declare module "@devup-api/fetch" {
56-
interface DevupApiServers {
57-
[\`openapi.json\`]: never
58-
}
59-
60-
interface DevupGetApiStruct {
61-
[\`openapi.json\`]: {
62-
[\`/users\`]: {};
63-
get_users: {};
64-
}
65-
}
66-
67-
interface DevupRequestComponentStruct {}
68-
69-
interface DevupResponseComponentStruct {}
70-
71-
interface DevupErrorComponentStruct {}
72-
}"
73-
`;
74-
75-
exports[`generateInterface returns interface for schema: %s 4`] = `
76-
"import "@devup-api/fetch";
77-
import type { DevupObject } from "@devup-api/fetch";
78-
79-
declare module "@devup-api/fetch" {
80-
interface DevupApiServers {
81-
[\`openapi.json\`]: never
82-
}
83-
84-
interface DevupGetApiStruct {
85-
[\`openapi.json\`]: {
86-
[\`/users\`]: {};
87-
getUsers: {};
88-
}
89-
}
90-
91-
interface DevupRequestComponentStruct {}
92-
93-
interface DevupResponseComponentStruct {}
94-
95-
interface DevupErrorComponentStruct {}
96-
}"
97-
`;
98-
99-
exports[`generateInterface returns interface for schema: %s 5`] = `
100-
"import "@devup-api/fetch";
101-
import type { DevupObject } from "@devup-api/fetch";
102-
103-
declare module "@devup-api/fetch" {
104-
interface DevupApiServers {
105-
[\`openapi.json\`]: never
106-
}
107-
108-
interface DevupGetApiStruct {
109-
[\`openapi.json\`]: {
110-
[\`/users\`]: {};
111-
getUsers: {};
112-
}
113-
}
114-
115-
interface DevupRequestComponentStruct {}
116-
117-
interface DevupResponseComponentStruct {}
118-
119-
interface DevupErrorComponentStruct {}
120-
}"
121-
`;
122-
123-
exports[`generateInterface returns interface for schema: %s 6`] = `
124-
"import "@devup-api/fetch";
125-
import type { DevupObject } from "@devup-api/fetch";
126-
12731
declare module "@devup-api/fetch" {
12832
interface DevupApiServers {
12933
[\`openapi.json\`]: never
@@ -166,7 +70,7 @@ declare module "@devup-api/fetch" {
16670
}"
16771
`;
16872

169-
exports[`generateInterface returns interface for schema: %s 7`] = `
73+
exports[`generateInterface handles nullable properties (OpenAPI 3.0 style) 1`] = `
17074
"import "@devup-api/fetch";
17175
import type { DevupObject } from "@devup-api/fetch";
17276

@@ -178,87 +82,41 @@ declare module "@devup-api/fetch" {
17882
interface DevupGetApiStruct {
17983
[\`openapi.json\`]: {
18084
[\`/users\`]: {
181-
response: Array<DevupObject<'response', 'openapi.json'>['User']>;
182-
};
183-
GetUsers: {
184-
response: Array<DevupObject<'response', 'openapi.json'>['User']>;
185-
};
186-
}
187-
}
188-
189-
interface DevupPostApiStruct {
190-
[\`openapi.json\`]: {
191-
[\`/users\`]: {
192-
response: DevupObject<'response', 'openapi.json'>['User'];
193-
};
194-
CreateUser: {
195-
response: DevupObject<'response', 'openapi.json'>['User'];
196-
};
197-
}
198-
}
199-
200-
interface DevupRequestComponentStruct {}
201-
202-
interface DevupResponseComponentStruct {
203-
[\`openapi.json\`]: {
204-
User: {
205-
id?: string;
206-
name?: string;
207-
};
208-
}
209-
}
210-
211-
interface DevupErrorComponentStruct {}
212-
}"
213-
`;
214-
215-
exports[`generateInterface returns interface for schema: %s 8`] = `
216-
"import "@devup-api/fetch";
217-
import type { DevupObject } from "@devup-api/fetch";
218-
219-
declare module "@devup-api/fetch" {
220-
interface DevupApiServers {
221-
[\`openapi.json\`]: never
222-
}
223-
224-
interface DevupGetApiStruct {
225-
[\`openapi.json\`]: {
226-
[\`/users\`]: {
227-
response: Array<DevupObject<'response', 'openapi.json'>['User']>;
228-
};
229-
get_users: {
230-
response: Array<DevupObject<'response', 'openapi.json'>['User']>;
231-
};
232-
}
233-
}
234-
235-
interface DevupPostApiStruct {
236-
[\`openapi.json\`]: {
237-
[\`/users\`]: {
238-
response: DevupObject<'response', 'openapi.json'>['User'];
85+
response?: {
86+
name?: string | null;
87+
age?: number | null;
88+
active?: boolean | null;
89+
tags?: Array<string> | null;
90+
metadata?: {
91+
key?: string;
92+
} | null;
93+
status?: "active" | "inactive" | null;
94+
};
23995
};
240-
create_user: {
241-
response: DevupObject<'response', 'openapi.json'>['User'];
96+
getUsers: {
97+
response?: {
98+
name?: string | null;
99+
age?: number | null;
100+
active?: boolean | null;
101+
tags?: Array<string> | null;
102+
metadata?: {
103+
key?: string;
104+
} | null;
105+
status?: "active" | "inactive" | null;
106+
};
242107
};
243108
}
244109
}
245110

246111
interface DevupRequestComponentStruct {}
247112

248-
interface DevupResponseComponentStruct {
249-
[\`openapi.json\`]: {
250-
User: {
251-
id?: string;
252-
name?: string;
253-
};
254-
}
255-
}
113+
interface DevupResponseComponentStruct {}
256114

257115
interface DevupErrorComponentStruct {}
258116
}"
259117
`;
260118

261-
exports[`generateInterface returns interface for schema: %s 9`] = `
119+
exports[`generateInterface handles nullable properties (OpenAPI 3.1 style) 1`] = `
262120
"import "@devup-api/fetch";
263121
import type { DevupObject } from "@devup-api/fetch";
264122

@@ -270,41 +128,31 @@ declare module "@devup-api/fetch" {
270128
interface DevupGetApiStruct {
271129
[\`openapi.json\`]: {
272130
[\`/users\`]: {
273-
response: Array<DevupObject<'response', 'openapi.json'>['User']>;
131+
response?: {
132+
name?: string | null;
133+
age?: number | null;
134+
active?: boolean | null;
135+
};
274136
};
275137
getUsers: {
276-
response: Array<DevupObject<'response', 'openapi.json'>['User']>;
277-
};
278-
}
279-
}
280-
281-
interface DevupPostApiStruct {
282-
[\`openapi.json\`]: {
283-
[\`/users\`]: {
284-
response: DevupObject<'response', 'openapi.json'>['User'];
285-
};
286-
createUser: {
287-
response: DevupObject<'response', 'openapi.json'>['User'];
138+
response?: {
139+
name?: string | null;
140+
age?: number | null;
141+
active?: boolean | null;
142+
};
288143
};
289144
}
290145
}
291146

292147
interface DevupRequestComponentStruct {}
293148

294-
interface DevupResponseComponentStruct {
295-
[\`openapi.json\`]: {
296-
User: {
297-
id?: string;
298-
name?: string;
299-
};
300-
}
301-
}
149+
interface DevupResponseComponentStruct {}
302150

303151
interface DevupErrorComponentStruct {}
304152
}"
305153
`;
306154

307-
exports[`generateInterface returns interface for schema: %s 10`] = `
155+
exports[`generateInterface handles nullable in component schemas 1`] = `
308156
"import "@devup-api/fetch";
309157
import type { DevupObject } from "@devup-api/fetch";
310158

@@ -314,22 +162,11 @@ declare module "@devup-api/fetch" {
314162
}
315163

316164
interface DevupGetApiStruct {
317-
[\`openapi.json\`]: {
318-
[\`/users\`]: {
319-
response: Array<DevupObject<'response', 'openapi.json'>['User']>;
320-
};
321-
getUsers: {
322-
response: Array<DevupObject<'response', 'openapi.json'>['User']>;
323-
};
324-
}
325-
}
326-
327-
interface DevupPostApiStruct {
328165
[\`openapi.json\`]: {
329166
[\`/users\`]: {
330167
response: DevupObject<'response', 'openapi.json'>['User'];
331168
};
332-
createUser: {
169+
getUsers: {
333170
response: DevupObject<'response', 'openapi.json'>['User'];
334171
};
335172
}
@@ -341,7 +178,8 @@ declare module "@devup-api/fetch" {
341178
[\`openapi.json\`]: {
342179
User: {
343180
id?: string;
344-
name?: string;
181+
nickname?: string | null;
182+
bio?: string | null;
345183
};
346184
}
347185
}

0 commit comments

Comments
 (0)