Skip to content

Commit

Permalink
fix: type empty object without additionalProperties as {}
Browse files Browse the repository at this point in the history
  • Loading branch information
mashabow committed Oct 31, 2023
1 parent 040f3eb commit e88a0f1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
10 changes: 8 additions & 2 deletions samples/empty-object-response-body/$api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
$path: () => `${prefix}${PATH1}`,
},
without_additional_properties: {
/**
* @returns OK
*/
delete: (option?: { config?: T | undefined } | undefined) =>
fetch<void, BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).send(),
fetch<Methods2['delete']['resBody'], BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).json(),
/**
* @returns OK
*/
$delete: (option?: { config?: T | undefined } | undefined) =>
fetch<void, BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).send().then(r => r.body),
fetch<Methods2['delete']['resBody'], BasicHeaders, Methods2['delete']['status']>(prefix, PATH2, DELETE, option).json().then(r => r.body),
$path: () => `${prefix}${PATH2}`,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ const api = <T>({ baseURL, fetch }: AspidaClient<T>) => {
const DELETE = 'DELETE';

return {
/**
* @returns OK
*/
delete: (option?: { config?: T | undefined } | undefined) =>
fetch<void, BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).send(),
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json(),
/**
* @returns OK
*/
$delete: (option?: { config?: T | undefined } | undefined) =>
fetch<void, BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).send().then(r => r.body),
fetch<Methods0['delete']['resBody'], BasicHeaders, Methods0['delete']['status']>(prefix, PATH0, DELETE, option).json().then(r => r.body),
$path: () => `${prefix}${PATH0}`,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
export type Methods = {
delete: {
status: 200

/** OK */
resBody: {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type Methods = {
resBody: {
limit: number
offset: number
data: {
}[]
}
}

Expand Down
2 changes: 2 additions & 0 deletions samples/openapi/api/v3/chats/_chatId@string/items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type Methods = {
resBody: {
limit: number
offset: number
data: {
}[]
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/builderUtils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ export const schema2value = (
} else if (isArraySchema(schema)) {
isArray = true;
value = schema2value(schema.items);
} else if (schema.properties || 'additionalProperties' in schema) {
} else if (schema.type === 'object' || schema.properties || 'additionalProperties' in schema) {
value = object2value(schema);
} else if (schema.format === 'binary') {
value = isResponse ? 'Blob' : BINARY_TYPE;
} else if (schema.type !== 'object') {
} else {
value = schema.type
? {
integer: 'number',
Expand Down

0 comments on commit e88a0f1

Please sign in to comment.