Skip to content

Commit e88a0f1

Browse files
committed
fix: type empty object without additionalProperties as {}
1 parent 040f3eb commit e88a0f1

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

samples/empty-object-response-body/$api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
3838
$path: () => `${prefix}${PATH1}`,
3939
},
4040
without_additional_properties: {
41+
/**
42+
* @returns OK
43+
*/
4144
delete: (option?: { config?: T | undefined } | undefined) =>
42-
fetch<void, BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).send(),
45+
fetch<Methods2['delete']['resBody'], BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).json(),
46+
/**
47+
* @returns OK
48+
*/
4349
$delete: (option?: { config?: T | undefined } | undefined) =>
44-
fetch<void, BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).send().then(r => r.body),
50+
fetch<Methods2['delete']['resBody'], BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).json().then(r => r.body),
4551
$path: () => `${prefix}${PATH2}`,
4652
},
4753
};

samples/empty-object-response-body/without-additional-properties/$api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
77
const DELETE = 'DELETE';
88

99
return {
10+
/**
11+
* @returns OK
12+
*/
1013
delete: (option?: { config?: T | undefined } | undefined) =>
11-
fetch<void, BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).send(),
14+
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json(),
15+
/**
16+
* @returns OK
17+
*/
1218
$delete: (option?: { config?: T | undefined } | undefined) =>
13-
fetch<void, BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).send().then(r => r.body),
19+
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json().then(r => r.body),
1420
$path: () => `${prefix}${PATH0}`,
1521
};
1622
};

samples/empty-object-response-body/without-additional-properties/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
export type Methods = {
33
delete: {
44
status: 200
5+
6+
/** OK */
7+
resBody: {
8+
}
59
}
610
}

samples/openapi/api/v3/channels/_channelId@string/chats/_chatId@string/items/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export type Methods = {
1616
resBody: {
1717
limit: number
1818
offset: number
19+
data: {
20+
}[]
1921
}
2022
}
2123

samples/openapi/api/v3/chats/_chatId@string/items/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export type Methods = {
1818
resBody: {
1919
limit: number
2020
offset: number
21+
data: {
22+
}[]
2123
}
2224
}
2325

src/builderUtils/converters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ export const schema2value = (
123123
} else if (isArraySchema(schema)) {
124124
isArray = true;
125125
value = schema2value(schema.items);
126-
} else if (schema.properties || 'additionalProperties' in schema) {
126+
} else if (schema.type === 'object' || schema.properties || 'additionalProperties' in schema) {
127127
value = object2value(schema);
128128
} else if (schema.format === 'binary') {
129129
value = isResponse ? 'Blob' : BINARY_TYPE;
130-
} else if (schema.type !== 'object') {
130+
} else {
131131
value = schema.type
132132
? {
133133
integer: 'number',

0 commit comments

Comments
 (0)