Carapacik / swagger_parser

Dart package that takes an OpenApi definition file and generates REST clients based on retrofit and data classes for your project.
https://pub.dev/packages/swagger_parser
MIT License
90 stars 38 forks source link

Handling content types #109

Closed elenaferr0 closed 10 months ago

elenaferr0 commented 10 months ago

I implemented the fix about the content type of the request which was discussed in issue #104. Let me know what you think of this solution, if everything is fine I can implement some more tests @Carapacik.

Carapacik commented 10 months ago

How about accepting the content type from yaml config so that it is more convenient to make the default type? To avoid writing @Header every time.

And it is better to make it a String type, because there may be many combinations, and it will not be possible to sort everything out.

elenaferr0 commented 10 months ago

So you mean like setting a default content-type for all requests of a given type? Like for example setting application/json-patch+json for all PATCH requests? Is there a way to do this globally for retrofit (or dio)? In regards to keeping the content-type as string then yes you're right, I'll fix that as soon as I can. Thanks!

Carapacik commented 10 months ago

So you mean like setting a default content-type for all requests of a given type? Like for example setting application/json-patch+json for all PATCH requests? Is there a way to do this globally for retrofit (or dio)?

Globally in dio init

elenaferr0 commented 10 months ago

I suppose you mean something like this:

Dio dio = Dio();
dio.options.headers['Content-Type'] = 'application/json';

Or equivalently setting it in Dio constructor. If there is another way let me know, I searched a bit the documentation but I didn't find anything else. I want all PATCH endpoints to use application/json-patch+json but all the others should use application/json. The problem with this solution is that (if I understand correctly) this would set the Content-Type header globally (which is not what I want, I'd like to set it only for some specific endpoints). I'm currently creating a single Dio instance with my configuration and interceptors and passing it to all clients. My other alternative would be to write a Dio interceptor that adds the Content-Type header I want only for PATCH requests, but this is a bit of a workaround and it's not really elegant.

Carapacik commented 10 months ago

I mean to make a default value for everything, and generate a header annotation for something different from it.

Carapacik commented 10 months ago

If there are any problems, then I can supplement your pr at the end of the week.

elenaferr0 commented 10 months ago

Oh okay sorry now I get what you're saying. I will implement this in the next days then. Thank you very much

Carapacik commented 10 months ago

@elenaferr0 Can I start my implementation?

elenaferr0 commented 10 months ago

Yes. Sorry I've been really busy, if you want you can start.

elenaferr0 commented 10 months ago

Thanks!