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

Argument of type '"/example/post-endpoint"' is not assignable to parameter of type 'PathsWithMethod<paths, "post">' #2021

Open
1 task
ViktorPontinen opened this issue Nov 27, 2024 · 2 comments
Assignees
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@ViktorPontinen
Copy link

ViktorPontinen commented Nov 27, 2024

Description

A brief description of the bug. Provide either a screenshot or the full error message
When we use the --path-params-as-types flag with openapi-typescript to generate types, some post requests(seems to only affect post requests) stop being autocompleted/discovered and shows error:
Argument of type '"/example/post-endpoint"' is not assignable to parameter of type 'PathsWithMethod<paths, "post">'.

Example(ignore the untyped body):

export const createSomeEntity = async (body) => {
  return client.POST('/example/post-endpoint', {
    body,
  })
}

Without the --path-params-as-types flag, everything works as expected. Only difference I see in generated types is the adjustments to dynamic paths keys: [path: `/example/dynamic/${string}`]:.

Anyone else got same issue or just us?

Reproduction

How can this be reproduced / when did the error occur? Does the issue occur in a specific browser, or all browsers?
Not sure if reproducible in other repos, I guess try to regenerate your types with the --path-params-as-types flag. Will try to test outside our repo to test.

Expected result
I think description covers it's all.
(in case it’s not obvious)

Checklist

@ViktorPontinen ViktorPontinen added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Nov 27, 2024
@kerwanp
Copy link
Contributor

kerwanp commented Dec 19, 2024

Hi @ViktorPontinen!

Could you provide an OpenAPI schema that result in the same behavior so we can reproduce your issue?

@ViktorPontinen
Copy link
Author

ViktorPontinen commented Dec 19, 2024

Hi @kerwanp , I was finally able to reproduce it in a smaller scope, our real openapi yaml has almost 97k lines and is auto-generated.
While doing so, I also think I figured out why it's happening. Unclear tho if this is because we structure our endpoints incorrectly or if it's just an edge-case that is not covered by openapi-fetch/openapi-typescript.

The paths "/api/sessions/create" and [path: `/api/sessions/${string}`] most likely collide because /create can also match the /${string} path.

Here is repo for reproduction, see /src/services/index.ts: https://github.com/ViktorPontinen/open-api-bug

EDIT: I now see the error is different, give me a minute to push updated.
EDIT TWO: Nvm, will take a while to figure it out. It's something else. Will post when ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

No branches or pull requests

2 participants