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

Parenthesis in path is included in parameter #503

Closed
gtflip opened this issue Aug 8, 2023 · 4 comments
Closed

Parenthesis in path is included in parameter #503

gtflip opened this issue Aug 8, 2023 · 4 comments

Comments

@gtflip
Copy link

gtflip commented Aug 8, 2023

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" } });
@ecyrbe
Copy link
Owner

ecyrbe commented Aug 8, 2023

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 ) ?

@gtflip
Copy link
Author

gtflip commented Aug 8, 2023

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!

@ecyrbe
Copy link
Owner

ecyrbe commented Aug 8, 2023

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

@ecyrbe
Copy link
Owner

ecyrbe commented Aug 10, 2023

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

@ecyrbe ecyrbe closed this as completed Aug 10, 2023
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