hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client
https://heyapi.vercel.app
Other
967 stars 77 forks source link

How can I customize withCredentials option in axios? #769

Closed soonoo closed 3 weeks ago

soonoo commented 1 month ago

Description

It seems that withCredentials option is hard coded when using axios client.
How can I set it?

grifondopala commented 1 month ago

Same question, but i am using client-fetch, and don't understand, how to set withCredentions to true. Need Help

soonoo commented 1 month ago

I haven't tried it yet, but I see that the generated code is exporting an configuration object named OpenAPI. It seems like importing and directly changing it is possible.

OpenAPI.WITH_CREDENTIALS = true
mrlubos commented 1 month ago

@grifondopala Are you using the legacy Fetch client or the standalone package?

grifondopala commented 1 month ago

I am using @hey-api/client-fetch

mrlubos commented 1 month ago

@soonoo I believe you're right about being hard-coded. This would be addressed by a standalone Axios client

mrlubos commented 1 month ago

@grifondopala you can pass any Fetch API arguments to the client when you're creating it. You could even supply your own fetch instance

grifondopala commented 1 month ago

@mrlubos you mean, that i should write createClient({ withCredentials: true }) ?

mrlubos commented 1 month ago

@grifondopala no, you will want to pass the native Fetch API option which is credentials. If you play with the StackBlitz example, you can see it's autocompleted in createClient(). withCredentials is the Axios API.

grifondopala commented 1 month ago

@mrlubos Than you! createClient({ credentials: "include" }) works for me

mrlubos commented 1 month ago

Hey @soonoo, if you're able to switch to the new Axios client, it's available there simply as passing withCredentials. More in the docs

mrlubos commented 1 month ago

I'm going to put a help wanted label on this as the new clients are a priority over maintaining the old ones

dagadbm commented 1 month ago

i wanted to use the new ones as well but the typescript of 5x is a deal breaker it breaks a lot of dependencies.

mrlubos commented 1 month ago

Is it @dagadbm? Because the main package has the same requirement https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/package.json#L70

mrlubos commented 1 month ago

Or do you mean you can't use the openapi-ts package at all?

dagadbm commented 1 month ago

I have the 0.33.2 version but I cannot update it any further because of the typescript.

I think the only thing that I can't do is mimick the axios error:

axios.interceptors.response.use(processData, processErrors);
OpenAPI.interceptors.response.use((request) => {
  if (request.status >= 200 || request.status <= 299) {
    return processData(request);
  } else {
    const error = new AxiosError<DatafoldError>(
      request.statusText,
      request.status,
      request.config,
      request.request,
      request,
    );
    return processErrors(error);
  }
});

i dont think things map out 1:1 from what I see.

But I won't take any more of your time. Its incredible how much stuff has ben evolving here.

mrlubos commented 1 month ago

@dagadbm I'll need to improve the Axios client, thanks for the feedback! That's a bummer about being stuck on v0.33.2, lots of good stuff since then. What kind of errors are you seeing? Any chance you know what has changed (presumably) in v0.34.0 that prevents you from upgrading?

dagadbm commented 1 month ago

Its the typescript requirement of 5.0

I cannot update it on my side I get a whole bunch of other conflicts with other packages.

mrlubos commented 1 month ago

Which version are you on?

mrlubos commented 3 weeks ago

Going to close this issue, please consider upgrading to the new clients. If anyone needs it for the legacy clients, we are open to pull requests. @dagadbm please open a separate issue if you think the TypeScript requirement should be addressed