Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to call delete since body is typed as never #469

Closed
oekstrand opened this issue Jun 5, 2023 · 8 comments
Closed

Unable to call delete since body is typed as never #469

oekstrand opened this issue Jun 5, 2023 · 8 comments

Comments

@oekstrand
Copy link

oekstrand commented Jun 5, 2023

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
  },
image
@ecyrbe
Copy link
Owner

ecyrbe commented Jun 5, 2023

this is a get path. You can call delete by passing undefined for body and it should work.

@ecyrbe ecyrbe closed this as completed Jun 5, 2023
@oekstrand
Copy link
Author

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()
  },

But still get this:
image

@oekstrand
Copy link
Author

oekstrand commented Jun 5, 2023

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?

@ecyrbe
Copy link
Owner

ecyrbe commented Jun 5, 2023

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.

@ecyrbe ecyrbe reopened this Jun 5, 2023
@oekstrand
Copy link
Author

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.

@ecyrbe
Copy link
Owner

ecyrbe commented Jun 5, 2023

ok, i reproduced the issue. it's triggered in some specific use cases. fix incoming.
in a few minutes

@ecyrbe
Copy link
Owner

ecyrbe commented Jun 5, 2023

can you check new version v10.9.1 and close the issue if it's fixed with this new version ?

@oekstrand
Copy link
Author

Yes, it works fine now. Thanks for the quick response and fix! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants