Skip to content

Commit 5bd37ba

Browse files
committed
Fix impossible body
1 parent e90632b commit 5bd37ba

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

packages/openapi-fetch/src/index.test.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe("client", () => {
233233

234234
// expect error on missing `body`
235235
// @ts-expect-error
236-
await client.get("/blogposts", {});
236+
await client.put("/blogposts", {});
237237

238238
// expect error on missing fields
239239
// @ts-expect-error
@@ -398,9 +398,8 @@ describe("client", () => {
398398
it("returns empty object on 204", async () => {
399399
const client = createClient<paths>();
400400
mockFetchOnce({ status: 204, body: "" });
401-
const { data, error, response } = await client.put("/tag/{name}", {
401+
const { data, error, response } = await client.del("/tag/{name}", {
402402
params: { path: { name: "New Tag" } },
403-
body: { description: "This is a new tag" },
404403
});
405404

406405
// assert correct data was returned

packages/openapi-fetch/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export type Params<T> = T extends { parameters: any } ? { params: NonNullable<T[
4747
export type RequestBodyObj<T> = T extends { requestBody?: any } ? T["requestBody"] : never;
4848
export type RequestBodyContent<T> = undefined extends RequestBodyObj<T> ? FilterKeys<NonNullable<RequestBodyObj<T>>, "content"> | undefined : FilterKeys<RequestBodyObj<T>, "content">;
4949
export type RequestBodyMedia<T> = FilterKeys<RequestBodyContent<T>, MediaType> extends never ? FilterKeys<NonNullable<RequestBodyContent<T>>, MediaType> | undefined : FilterKeys<RequestBodyContent<T>, MediaType>;
50-
export type RequestBody<T> = undefined extends RequestBodyMedia<T> ? { body?: RequestBodyMedia<T> } : { body: RequestBodyMedia<T> };
50+
export type RequestBody<T> = RequestBodyMedia<T> extends never ? { body?: never } : undefined extends RequestBodyMedia<T> ? { body?: RequestBodyMedia<T> } : { body: RequestBodyMedia<T> };
5151
export type QuerySerializer<T> = (query: T extends { parameters: any } ? NonNullable<T["parameters"]["query"]> : Record<string, unknown>) => string;
5252
export type BodySerializer<T> = (body: RequestBodyMedia<T>) => any;
5353
export type RequestOptions<T> = Params<T> &

packages/openapi-fetch/test/v1.d.ts

+12
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ export interface paths {
153153
500: components["responses"]["Error"];
154154
};
155155
};
156+
delete: {
157+
parameters: {
158+
path: {
159+
name: string;
160+
};
161+
};
162+
responses: {
163+
/** @description No Content */
164+
204: never;
165+
500: components["responses"]["Error"];
166+
};
167+
};
156168
parameters: {
157169
path: {
158170
name: string;

packages/openapi-fetch/test/v1.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ paths:
160160
$ref: '#/components/responses/CreateTag'
161161
500:
162162
$ref: '#/components/responses/Error'
163+
delete:
164+
responses:
165+
204:
166+
description: No Content
167+
500:
168+
$ref: '#/components/responses/Error'
163169
/default-as-error:
164170
get:
165171
responses:

0 commit comments

Comments
 (0)