psrebniak / swagger-typescript-client-generator

MIT License
13 stars 4 forks source link

Response type #17

Open j3bb9z opened 4 years ago

j3bb9z commented 4 years ago

Hi,

Thanks for providing this generator, it's great!

However, I have one small issue. It assumes global Response type, which comes from browser Fetch API and which doesn't exist in node.js applications.

I think it would be better to allow generic response type. That way we can use any request factory we like, not necessarily implementing the browser Fetch API Response.

psrebniak commented 4 years ago

Hello You can use isomorphic-fetch to provide fetch func and API to nodejs.

But you’re right that more generic solution is needed. What solution to support for custom response types do you prefer?

Wiadomość napisana przez Jacob B. notifications@github.com w dniu 22.12.2019, o godz. 10:39:

 Hi,

Thanks for providing this generator, it's great!

However, I have one small issue. It assumes global Response type, which comes from browser Fetch API and which doesn't exist in node.js applications.

I think it would be better to allow generic response type. That way we can use any request factory we like, not necessarily implementing the browser Fetch API Response.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

j3bb9z commented 4 years ago

Yeah, I know there are some libraries that provide browser-like fetch method. I tried to avoid isomorphic-fetch, mainly because last release was like 4 years ago. I also tried node-fetch but it doesn't have some of the Response properties, like formData and trailer.

I don't know yet, how we could make it more generic while still maintaining typing for response objects. Let's say, we have Something response object. Now it's generated as Promise<ApiResponse<Something>> return type.

In my case Promise<Something>> would be sufficient, but that would break typing if someone actually wants it to be wrapped in Response. Also, someone could want AxiosResponse for example.

I'm in no way a typescript expert, so I don't know if it's possible to make some kind of generic Promise<T<Something>> return type, based on request factory passed to client constructor. Seems complicated, but I'll try to figure out something. Maybe you have some idea how it can be solved?

Meanwhile, I guess, I'll go with isomorphic-fetch.

psrebniak commented 4 years ago

@jacob87o2 next major version v2 it will be configurable by new YourClient<ResponseType> Added to milestone

j3bb9z commented 4 years ago

@psrebniak Awesome news! Thanks!