ecyrbe / zodios

typescript http client and server with zod validation

Home Page:https://www.zodios.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parenthesis in path is included in parameter

gtflip opened this issue · comments

commented

This is for a third-party API, so I don't have control over the API. One of the paths is "/api/v1/odata/Jobs(:Id)". In the "params" object, it has a key of "Id)". I generated the code with openapi-zod-client. I simplified the swagger file to just one of the paths with that format.

import { makeApi, Zodios, type ZodiosOptions } from "@zodios/core";
import { z } from "zod";

const endpoints = makeApi([
  {
    method: "get",
    path: "/api/v1/odata/Jobs(:Id)",
    alias: "Job_GetById",
    requestFormat: "json",
    parameters: [
      {
        name: "Id",
        type: "Path",
        schema: z.number(),
      },
    ],
    response: z.void(),
  },
]);

export const api = new Zodios(endpoints);

export function createApiClient(baseUrl: string, options?: ZodiosOptions) {
  return new Zodios(baseUrl, endpoints, options);
}

When I use it, "Id)" is the completion vscode gives me instead of "Id". Removing the parenthesis gives me an error.

  const client = createApiClient("");
  await client.Job_GetById({ params: { "Id)": "1234" } });
commented

can you try adding a // @ts-expect-error and see if it's just a compile time issue and if at runtime it works when removing the ) ?

commented

I was having problems getting an API token, but now that I have, I tried it with { Id: 1000 } and it worked properly. So, it's just a type problem.

If it had the correct key, would it also be restricted to number?

Thanks!

commented

yes it would. i'll check if this pending PR solves your issue : #486

commented

This is now fixed in @zodios/core v10.9.3