enkot / nuxt-open-fetch

Generate zero-overhead, typed OpenAPI clients for Nuxt.
https://nuxt-open-fetch.vercel.app
MIT License
114 stars 10 forks source link

Cannot write post-request with request body #37

Closed uykusuz closed 2 months ago

uykusuz commented 2 months ago

Hi,

thank you for your work in this module!

I want to do a post request with a request body. I created a changeset of the problem here.

I add the following line to playground/app.vue:

await $pets('/store/order', { body: { petId: petId.value }})

That won't compile with the following error: Argument of type '{ body: { petId: number; }; }' is not assignable to parameter of type 'OpenFetchOptions<"post" | "POST", "post", { post: { requestBody?: { content: { "application/json": { id?: number | undefined; petId?: number | undefined; quantity?: number | undefined; shipDate?: string | undefined; status?: "placed" | ... 2 more ... | undefined; complete?: boolean | undefined; }; "application/xml":...'. Property 'method' is missing in type '{ body: { petId: number; }; }' but required in type '{ method: "post" | "POST"; }'.ts(2345) fetch.ts(14, 77): 'method' is declared here.

When I do what TS wants, i.e. add that method parameter with a value of "post" it doesn't work either. Now it tells me the following: Argument of type '{ method: "post"; body: { petId: number; }; }' is not assignable to parameter of type 'OpenFetchOptions<"post", "post", { post: { requestBody?: { content: { "application/json": { id?: number | undefined; petId?: number | undefined; quantity?: number | undefined; shipDate?: string | undefined; status?: "placed" | ... 2 more ... | undefined; complete?: boolean | undefined; }; "application/xml": { ...; }...'. Type '{ method: "post"; body: { petId: number; }; }' is not assignable to type 'Record<string, never>'.ts(2345)

I tried digging into types, tried google, I cannot find the cause of the problem.

Is this a bug in nuxt-open-fetch or am I doing something wrong?

Thank you in advance for your response!

Regards, Boris

enkot commented 2 months ago

Hi @uykusuz,

Good catch, it's definitely a bug!

enkot commented 2 months ago

@uykusuz Fixed in v0.7.0

uykusuz commented 2 months ago

Wow awesome, thank you!

-------- Original Message -------- On Apr 13, 2024, 11:48, Taras Batenkov wrote:

Closed #37 as completed.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>