swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.01k stars 6.03k forks source link

[PHP] Add option to generate client without Guzzle #5305

Open baartosz opened 7 years ago

baartosz commented 7 years ago
Description

Follow up on discussions that took place in https://github.com/swagger-api/swagger-codegen/pull/5190 and https://github.com/swagger-api/swagger-codegen/issues/1482. In some cases dependency on guzzle may be a problem and it should be possible to use any other psr7-compatible client. Its should not be a big deal considering that generated client is already using psr7 compatible request and response objects.

Swagger-codegen version

2.3.0+

Swagger declaration file content or url

n/a

Command line used for generation

--library=none or something

Steps to reproduce

n/a

Related issues

https://github.com/swagger-api/swagger-codegen/pull/5190 https://github.com/swagger-api/swagger-codegen/issues/1482

Suggest a Fix

n/a

soullivaneuh commented 5 years ago

The best would be to use php-http directly as it provide HTTP client abstraction with PSR7 interfaces compliance and allows end user to choose which one to use: http://docs.php-http.org/en/latest/clients.html

It simple and used by a lot of PHP libraries now: https://packagist.org/packages/php-http/httplug/dependents

I see it was proposed in https://github.com/swagger-api/swagger-codegen/pull/5190/files#r108366631 but removed, why?

dbu commented 5 years ago

unless you need async requests, i would not depend on the httplug client interface but the psr-18 interface directly, and psr-17 for the factory for requests.

php-http offers a bunch of clients implementing the client interface, and the next guzzle version is expected to implement psr-18 directly. the way to go would be to require a psr/http-client-implementation and then let the user configure the library with a client or potentially use php-http/discovery to automatically discover an available client.

judgej commented 5 years ago

Would this be something to implement as an option, or just as another type of generated output? If I wanted to pay with this approach, is there any way to wrap the output as a plugable module? I can imagine there are many dozens of generated code that people may want to produce (for example, I would like to generate just the message generation without any client) so there is surely a way that can be done without forking and modifying the whole application?

Healyhatman commented 1 year ago

It'd be very nice to for example pass in my own client, like a wrapper for Laravel's HTTP factory

dbu commented 1 year ago

i would suggest to have an optional psr ClientInterface argument and when it is not passed use php-http/discovery to autodiscover a psr-18 client. since recently php-http/discovery even installs a suitable client if the project contains none and your library requires psr/http-client-implementation