Unable to call delete since body is typed as never
oekstrand opened this issue · 8 comments
Given the schema below, I am unable to call delete on it since the data param is typed as never.
Schema
{
method: 'get',
path: '/api/customers/:customerId/subscriptions/:subscriptionId/resources/ifm/:resourceId',
requestFormat: 'json',
parameters: [
{
name: 'customerId',
type: 'Path',
schema: z.string().uuid()
},
{
name: 'subscriptionId',
type: 'Path',
schema: z.string().uuid()
},
{
name: 'resourceId',
type: 'Path',
schema: z.string().uuid()
}
],
response: IFMResource
},
this is a get path. You can call delete by passing undefined for body and it should work.
Sorry, pasted the wrong schema, here's the correct one:
{
method: 'delete',
path: '/api/customers/:customerId/subscriptions/:subscriptionId/resources/intunefourme/:resourceId',
requestFormat: 'json',
parameters: [
{
name: 'customerId',
type: 'Path',
schema: z.string().uuid()
},
{
name: 'subscriptionId',
type: 'Path',
schema: z.string().uuid()
},
{
name: 'resourceId',
type: 'Path',
schema: z.string().uuid()
}
],
response: z.void()
},
Update, I created a new project with just zodios and an empty schema and added the faulting endpoint, which worked. Then added the other endpoints one by one, when I added another delete endpoint which had a body defined, I got the error again:
Here's an example that reproduces the erorr:
import { makeApi, Zodios, ZodiosPathsByMethod, type ZodiosOptions } from "@zodios/core";
import { z } from "zod";
const DeleteRoleAssignmentCommand = z.object({ tenantId: z.string().uuid(), objectId: z.string().uuid() });
const endpoints = makeApi([
{
method: "delete",
path: "/api/customers/:customerId/",
requestFormat: "json",
parameters: [
{
name: "customerId",
type: "Path",
schema: z.string().uuid(),
}
],
response: z.void(),
},
{
method: "delete",
path: "/api/customers/:customerId/roleassignments/:roleId",
requestFormat: "json",
parameters: [
{
name: "body",
type: "Body",
schema: DeleteRoleAssignmentCommand,
},
{
name: "roleId",
type: "Path",
schema: z.string().uuid(),
},
{
name: "customerId",
type: "Path",
schema: z.string(),
},
],
response: z.void(),
},
]);
export const api = new Zodios(endpoints);
export function createApiClient(baseUrl: string, options?: ZodiosOptions) {
return new Zodios(baseUrl, endpoints, options);
}
const client = createApiClient("http://localhost:3000/");
client.delete("/api/customers/:customerId/", undefined, { params: { customerId: "123", subscriptionId: "456", resourceId: "789" } });
@ecyrbe Do you want me to open a new issue for this since you closed it?
If you have a body, put the body instead of undefined.
But let me check, should allow undefined param if no body.
Reopening. Please also provide version of zodios used.
Ok, so to be clear I have endpoint A that accepts a body and endpoint B that doesn't accept a body. I want to call endpoint B,
but it seems like having the other endpoint with a body in the endpoints array cause the typing to resolve to never.
Using zodios version 10.9.0.
ok, i reproduced the issue. it's triggered in some specific use cases. fix incoming.
in a few minutes
can you check new version v10.9.1
and close the issue if it's fixed with this new version ?
Yes, it works fine now. Thanks for the quick response and fix! 🚀