What's the right way to handle chunked json response with swagger and autogenerated php client?
one text
Solution:
Do answer my own question it is possible, but not easily - meaning there is no option or parameter.
First create a class that extends the autogenerated API class. There you have access to all of the protected methods. We assume the endpoint or api method is called testMethodGet
. The only thing that can be reused is the request method, i.e. testMethodGetRequest
, but it does all of the client side validation and transforming of input data, so that's already a big win. Do also get some of the boilerplate result validation you can copy the "http info method", i.e. testMethodGetWithHttpInfo
(use async version if you wish). Remove the if/else block after $responseBody = $response->getBody();
and in the return replace the ObjectSearializer line with just $responseBody
.
What you are now getting back is the body as PSR7 stream, but there is one last catch. By default the whole response is drained into a temporary file. To really stream the result body from the server in the created method add an option to $options: $options['stream'] = true;
Now the method returns as soon as the body is started. No need to wait for the whole body content.
One more thing. As the result is a PSR7 stream you can use $stream->detach()
to get the PHP stream resource if you prefer to use the normal file and stream methods.