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

fix request body type detection when using headers, cookies #23

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

fedorg
Copy link

@fedorg fedorg commented Apr 20, 2022

The library had trouble detecting the POST body payload types of my API. The argument was being typed as an empty object, and preventing me from sending any payloads. I had to use hacks such as these to make things work:

type CreateStationArg = components['schemas']['CreateStation'] // type hack
export const CreateStation = (arg: CreateStationArg, init?: RequestInit) => fetcher.path("/stations").method("post").create()(arg as any, init)

Instead of this:

export const CreateStation2 = fetcher.path("/stations").method("post").create()
// const CreateStation2: (arg: Record<string, never>, init?: RequestInit | undefined) => ...

This PR fixes this by changing the inference of OpArgType slightly. This allows for these types of POST payloads to be sent.
I have also added a test for a slice of my problematic API.

@fedorg
Copy link
Author

fedorg commented Apr 25, 2022

Since the merge request has stalled, I have published my version on NPM: @fedorg/openapi-typescript-fetch
You can use if you have the same issue with Record<string, never> showing up in arguments. Use at least version ^1.1.3

@ajaishankar
Copy link
Owner

HI @fedorg there are a couple of commits in master that has not yet been released (my bad) and a fix addressing this exact issue is one of them b62ee71. Will release the pending changes today, sorry about the confusion and your time...

@duncanbeevers
Copy link

These changes were released in 1.1.3. I think this PR should be closed.

@Rendez Rendez mentioned this pull request Apr 20, 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

Successfully merging this pull request may close these issues.

3 participants