-
Notifications
You must be signed in to change notification settings - Fork 119
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
Added the 'expose_http_client' flag #453
Added the 'expose_http_client' flag #453
Conversation
Codecov Report
@@ Coverage Diff @@
## master #453 +/- ##
==========================================
- Coverage 75.51% 75.48% -0.03%
==========================================
Files 9 9
Lines 964 971 +7
==========================================
+ Hits 728 733 +5
- Misses 236 238 +2
|
You can create ChopperClient and provide to it custom httpClient with all proxies. So my question is why you cannot send configured ChopperClient(with HttpClient inside) instead of HttpClient? |
To make the library easier to use. Having to create the One could argue the same about static PetServiceJson create(
{ChopperClient? client,
Authenticator? authenticator,
String? baseUrl,
Iterable<dynamic>? interceptors}) {
if (client != null) {
return _$PetServiceJson(client);
}
final newClient = ChopperClient(
services: [_$PetServiceJson()],
converter: $JsonSerializableConverter(),
interceptors: interceptors ?? [],
authenticator: authenticator,
baseUrl: baseUrl ?? 'http://petstore.swagger.io/v2');
return _$PetServiceJson(newClient);
} Optionally adding the The way I've added it also makes it entirely optional, so it doesn't cause anything to be backward incompatible. |
I'm closing the PR because you can expose ChopperClient even without these changes. |
@Vovanella95 Can you elaborate on how it's possible to expose the |
Hi @Dumoulin-Lander , you can do this when create service instance: final newClient = ChopperClient(
converter: $JsonSerializableConverter(),
//any parameters you want
);
final service = PetServiceJson.create(client: newClient); |
Thanks for the quick response! I find myself agreeing with Jeroen here I think. The way you're proposing gives you ways to retain a reference to the I guess the ship has sailed on this PR, I'll figure something out myself. Thanks again! |
Feel free to use my forked repository, I'm don't plan on removing it since I'm using this fork in some of my other projects. |
There's already an issue fixed in this main repository that is valuable for me, so I'd rather use it so we can get updates when needed. Also, hi Jeroen :) |
@Dumoulin-Lander if it's really important, ok we can merge it :) I am reopening PR, please ensure CI proccess is succeed |
@Dumoulin-Lander please resolve conflicts |
We can expose ChopperClient without this PR. Closing it. |
I want to be able to supply a http client to the generated code. This is useful for configuring things like proxies but also for unit testing.
I've added a build option
expose_http_client
that you can add in thebuild.yaml
.With the flag set to
false
(default), the code remains exactly as it was before adding this feature.When it's enabled the following is generate:
The reason why I put this behind a flag is because you need a dependency to
http
when you want to accepthttp.Client
as a parameter, which would be a breaking change.