-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[PHP] API client using guzzle6 & psr7 instead of curl #5190
Conversation
I'm all for dropping the shipped client as it will make the generated code much more simple, focus of this projects is not to generate HTTP clients. The problem I see is relying directly on Guzzle interface directly, the whole point of PSR-7 is NOT to do that. Generated code should rely on PSR-7 exclusively and enable me to use whatever compatible implementation. This would make integrating the SDK much harder than it should be. For example, you might already have a PSR-7 compatible client in your app pre-configured, you should be able to just inject it and use it. This means generated code should rely on functionality provided by the interface, for example Streams. |
Also: having this behind an option seems reasonable, but I think it would make supporting other libraries messy. What I feel would be a much cleaner approach is to do a "base" PSR-7 only implementation which wouldn't be able to work without injecting the client at all. Then, |
@dkarlovi i see your point. So basically instead of httplug provide own interface for the client and optional --library to have one already there? guzzle/psr7 now is used to provide helpers e.g. To build multipart requests. Are you suggesting writing it from scratch instead? |
@baartosz pretty much, yes. If you have a functional PSR-7 client enabled, you can just inject it and have it work with the generated SDK. For example, your HTTP client might have a logger set up which stores all requests to Elastic search, you don't want to have another client which does the same thing, but lacks integration to your environment. I don't suggest writing anything from scratch, no, the whole point of removing the HTTP client is avoid doing that. :) Can you point me to where exactly you're constructing multi-part messages? It might be an XY problem. |
@baartosz BTW thank you very much for your contribution, it's a great effort on your part. |
@dkarlovi makes sense. At this point generated client is using psr7 compatible request and response, so client itself is easy to replace with whatever is decided. Multipart stream from Thanks for feedback. |
* @var string | ||
*/ | ||
protected $curlConnectTimeout = 0; | ||
protected $host = '{{basePath}}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use unescape basePath instead: {{{basePath}}}
@@ -123,51 +109,6 @@ class Configuration | |||
protected $tempFolderPath; | |||
|
|||
/** | |||
* Indicates if SSL verification should be enabled or disabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that the SSL, proxy and timeout methods have been removed. Can you share more with me how a developer will set SSL, proxy, timeout in the new client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wing328 idea is to remove the HTTP client implementation completely and inject a PSR-7 capable client such as Guzzle.
This means setting up these kinds of configuration would be outside of scope of generated code, it would assume the injected client is capable of being configured properly in its own right. This code would just use it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkarlovi thanks for explaining more. To ease the migration, I think we will need to provide auto-generated documentation on how to set these values using Guzzle (the default PSR-7 http client)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wing328 Need some guidance here. I am not sure about priorities - is it more important to have working client out of the box, or having more flexible one?
Should we add client or httplug+client dependencies by default?
Is enough to provide generated apis classes calling send($request)
on some ApiClientInterface
, and expect users to choose client library and select/create adapter?
Or maybe leave no-client version as default and add --library=httplug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a suggested flow which makes sense to me:
- generate no implementation dependency by default, this will generate a "clean" version, add additional info / sample code on how to inject own HTTP client
- generate an additional class if
--library=httplug
is provided, this version is basically 1) with an additional item in composer.json and a HTTP client pre-injected for you (so, you can still inject another client yourself if you don't want to use the additional class, it just doesn't install a depenency you might not want by default)
We might make 2) the default to keep BC though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wing328 sounds good to me, documentation should note how to create a "bare" version, for example --library=psr7
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Settled then. I'll update this PR soon with default version (with guzzle as its easier to use than httplug) and add --library=psr7
later as separate feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@baartosz Guzzle is a better choice as you don't need an abstraction since PSR7 is your preferred abstraction, no need for an abstraction over an abstraction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@baartosz want to test&adopt your httplug client + guzzle. Good time to make it a try? would I wait a little for your " I'll update this PR soon with default version.."
thx a lot for your work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@richhl guzzle6-only version is almost ready, it will be better to wait for it instead of reviewing and re-reviewing later.
Currently readme.md says that client works with php 5.4 which is not maintained for 1,5 years Should default version work with |
I would say go for as new a version as needed. For this new way of doing it I don't see a need to forcefully stay behind on old PHP versions. |
@@ -123,51 +109,6 @@ class Configuration | |||
protected $tempFolderPath; | |||
|
|||
/** | |||
* Indicates if SSL verification should be enabled or disabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, rebased, tested with php 7 and 5.5, ready to review. Unfortunately python test suite is breaking build for some reason.
|
@baartosz don't worry about the Python test failure. I've fixed it in the master. (I'll run some tests later and let you know if I've any feedback) |
do you want us to test @baartosz ? any guidance to test it?
Thx in advance.
…___________________________
Richard C. Hidalgo Lorite
Director de Sistemas
ISI Argonauta, S.L.
C/Alcalá 196, apto. 13, 28028 Madrid
Telf: +34 691 502 235
http://www.argonauta.org
2017-03-30 19:17 GMT+02:00 baartosz <notifications@github.com>:
Updated, rebased, tested with php 7 and 5.5, ready to review.
Httplug removed, guzzle6 added, required php increased to 5.5.
Unfortunately python test suite is breaking build for some reason.
[INFO] Python Swagger Petstore Client .................... FAILURE [20.635s]
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5190 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABBlDpFdWB23-vgCYInJym82cp51YyzUks5rq-O8gaJpZM4MorY->
.
|
@richhl here are the steps to test it
Then you can use the JAR to generate PHP API client by providing a spec. |
The Travis CI tests passed: https://travis-ci.org/swagger-api/swagger-codegen/builds/217127129 |
I used PHP CodeSniffer to inspect the code and found some enhancements (code format) we can make to the PHP API client (this PR and master). I'll create a separate task for tracking. |
…ialization in some tests
just a rebase to solve conflicts |
@baartosz PR merged into 2.3.0. Thanks for the huge enhancement! I'm sure the community appreciates your effort. |
@baartosz awesome work! |
don't worry @baartosz! hundred of eyes and hands are ready now to test and contribute changes if any. we expect to test this week and next. will get in touch. thx 4 your work |
@baartosz I did review the code and play around with it over the weekend. Like any other generators, I would expect it to improve over time thanks to the vibrant community. |
FYI. Updated README to include @baartosz as the template owner of PHP Guzzle |
Hello, Not sure if this is the right place, but I'm wanting to use the template specified in this PR and I can't find any documentation on how I go about using it. If you guys could point me in the right direction, I would really appreciate it! Thanks in advance, |
@Robert430404 Please open a new issue with the question instead. |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates)2.3.0
branch for breaking (non-backward compatible) changes.Description of the PR
Finally finished #1482. Looks massive but without generated samples its roughly 10 files changed plus few new test classes. Large feature anyway.
Important points:
php-http/guzzle6-adapter
+guzzlehttp/guzzle
) and curl client (php-http/curl-client
). Works nice with both of them. Only thing not working currently with curl client was file upload. I left it for another iteration/separate ticket. Tests are currently ran only with guzzle.$response->getHeader($name);
(its how psr7 expects it to work)Please let me know if its better to make it optional like
--library=httplug
or something.