From 77930aec6b09734a098a9c914d94615d0b88c566 Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Sun, 22 Sep 2024 22:37:21 +0200 Subject: [PATCH] use multipart --- .../Client/Language/php-operation.php.twig | 12 +++---- .../Generator/Client/resource/php/Client.php | 12 +++---- .../Client/resource/php_collection/BarTag.php | 4 +-- .../resource/php_collection/FooBarTag.php | 4 +-- .../resource/php_collection/FooBazTag.php | 4 +-- .../resource/php_content_type/Client.php | 28 +++++++-------- .../php_content_type/JsonException.php | 8 ++--- .../php_content_type/MultipartException.php | 8 ++--- .../resource/php_test/JsonException.php | 8 ++--- .../resource/php_test/MultipartException.php | 8 ++--- .../Client/resource/php_test/ProductTag.php | 34 +++++++++---------- 11 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/Generator/Client/Language/php-operation.php.twig b/src/Generator/Client/Language/php-operation.php.twig index cbb9931..5893391 100644 --- a/src/Generator/Client/Language/php-operation.php.twig +++ b/src/Generator/Client/Language/php-operation.php.twig @@ -26,7 +26,7 @@ {% elseif operation.bodyContentType %} 'Content-Type' => '{{ operation.bodyContentType }}', {% elseif operation.bodyName %} - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', {% endif %} ], 'query' => $this->parser->query([ @@ -40,13 +40,13 @@ ]), {% if operation.bodyName %} {% if operation.bodyContentShape == 'application/octet-stream' or operation.bodyContentShape == 'application/xml' or operation.bodyContentShape == 'text/plain' %} - 'body' => ${{ operation.bodyName }} + 'body' => ${{ operation.bodyName }}, {% elseif operation.bodyContentShape == 'application/x-www-form-urlencoded' %} - 'form_params' => ${{ operation.bodyName }} + 'form_params' => ${{ operation.bodyName }}, {% elseif operation.bodyContentShape == 'multipart/form-data' %} - 'multipart' => ${{ operation.bodyName }} + 'multipart' => ${{ operation.bodyName }}->getParts(), {% else %} - 'json' => ${{ operation.bodyName }} + 'json' => ${{ operation.bodyName }}, {% endif %} {% endif %} ]; @@ -90,7 +90,7 @@ {% if in_throw %} {% endif %}$data = \json_decode((string) $body); {% elseif payload.contentShape == 'multipart/form-data' %} {% if in_throw %} {% endif %}// @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed - {% if in_throw %} {% endif %}$data = []; + {% if in_throw %} {% endif %}$data = new \Sdkgen\Client\Multipart(); {% elseif payload.contentShape == 'text/plain' or payload.contentShape == 'application/xml' %} {% if in_throw %} {% endif %}$data = (string) $body; {% else %} diff --git a/tests/Generator/Client/resource/php/Client.php b/tests/Generator/Client/resource/php/Client.php index ff3ad54..7cdf948 100644 --- a/tests/Generator/Client/resource/php/Client.php +++ b/tests/Generator/Client/resource/php/Client.php @@ -88,12 +88,12 @@ public function create(string $name, string $type, EntryCreate $payload): EntryM $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { @@ -145,12 +145,12 @@ public function update(string $name, string $type, \PSX\Record\Record $payload): $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { @@ -239,12 +239,12 @@ public function patch(string $name, string $type, array $payload): array $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { diff --git a/tests/Generator/Client/resource/php_collection/BarTag.php b/tests/Generator/Client/resource/php_collection/BarTag.php index 98044df..03e1808 100644 --- a/tests/Generator/Client/resource/php_collection/BarTag.php +++ b/tests/Generator/Client/resource/php_collection/BarTag.php @@ -66,12 +66,12 @@ public function put(EntryCreate $payload): EntryMessage $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { diff --git a/tests/Generator/Client/resource/php_collection/FooBarTag.php b/tests/Generator/Client/resource/php_collection/FooBarTag.php index ea20345..0ea869c 100644 --- a/tests/Generator/Client/resource/php_collection/FooBarTag.php +++ b/tests/Generator/Client/resource/php_collection/FooBarTag.php @@ -65,12 +65,12 @@ public function create(EntryCreate $payload): EntryMessage $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { diff --git a/tests/Generator/Client/resource/php_collection/FooBazTag.php b/tests/Generator/Client/resource/php_collection/FooBazTag.php index 7e86da8..dc09306 100644 --- a/tests/Generator/Client/resource/php_collection/FooBazTag.php +++ b/tests/Generator/Client/resource/php_collection/FooBazTag.php @@ -66,12 +66,12 @@ public function create(EntryCreate $payload): EntryMessage $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { diff --git a/tests/Generator/Client/resource/php_content_type/Client.php b/tests/Generator/Client/resource/php_content_type/Client.php index 02f3135..87645e1 100644 --- a/tests/Generator/Client/resource/php_content_type/Client.php +++ b/tests/Generator/Client/resource/php_content_type/Client.php @@ -35,7 +35,7 @@ public function binary(\Psr\Http\Message\StreamInterface $body): \Psr\Http\Messa 'query' => $this->parser->query([ ], [ ]), - 'body' => $body + 'body' => $body, ]; try { @@ -81,7 +81,7 @@ public function form(array $body): array 'query' => $this->parser->query([ ], [ ]), - 'form_params' => $body + 'form_params' => $body, ]; try { @@ -112,12 +112,12 @@ public function form(array $body): array } /** - * @param \stdClass $body - * @return \stdClass + * @param mixed $body + * @return mixed * @throws JsonException * @throws ClientException */ - public function json(\stdClass $body): \stdClass + public function json(mixed $body): mixed { $url = $this->parser->url('/json', [ ]); @@ -129,7 +129,7 @@ public function json(\stdClass $body): \stdClass 'query' => $this->parser->query([ ], [ ]), - 'json' => $body + 'json' => $body, ]; try { @@ -158,12 +158,12 @@ public function json(\stdClass $body): \stdClass } /** - * @param array $body - * @return array + * @param \Sdkgen\Client\Multipart $body + * @return \Sdkgen\Client\Multipart * @throws MultipartException * @throws ClientException */ - public function multipart(array $body): array + public function multipart(\Sdkgen\Client\Multipart $body): \Sdkgen\Client\Multipart { $url = $this->parser->url('/multipart', [ ]); @@ -174,7 +174,7 @@ public function multipart(array $body): array 'query' => $this->parser->query([ ], [ ]), - 'multipart' => $body + 'multipart' => $body->getParts(), ]; try { @@ -182,7 +182,7 @@ public function multipart(array $body): array $body = $response->getBody(); // @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed - $data = []; + $data = new \Sdkgen\Client\Multipart(); return $data; } catch (ClientException $e) { @@ -193,7 +193,7 @@ public function multipart(array $body): array if ($statusCode === 500) { // @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed - $data = []; + $data = new \Sdkgen\Client\Multipart(); throw new MultipartException($data); } @@ -222,7 +222,7 @@ public function text(string $body): string 'query' => $this->parser->query([ ], [ ]), - 'body' => $body + 'body' => $body, ]; try { @@ -268,7 +268,7 @@ public function xml(string $body): string 'query' => $this->parser->query([ ], [ ]), - 'body' => $body + 'body' => $body, ]; try { diff --git a/tests/Generator/Client/resource/php_content_type/JsonException.php b/tests/Generator/Client/resource/php_content_type/JsonException.php index 54c6b0f..a777035 100644 --- a/tests/Generator/Client/resource/php_content_type/JsonException.php +++ b/tests/Generator/Client/resource/php_content_type/JsonException.php @@ -10,9 +10,9 @@ class JsonException extends KnownStatusCodeException { - private \stdClass $payload; + private mixed $payload; - public function __construct(\stdClass $payload) + public function __construct(mixed $payload) { parent::__construct('The server returned an error'); @@ -20,9 +20,9 @@ public function __construct(\stdClass $payload) } /** - * @return \stdClass + * @return mixed */ - public function getPayload(): \stdClass + public function getPayload(): mixed { return $this->payload; } diff --git a/tests/Generator/Client/resource/php_content_type/MultipartException.php b/tests/Generator/Client/resource/php_content_type/MultipartException.php index 5579699..450fbf8 100644 --- a/tests/Generator/Client/resource/php_content_type/MultipartException.php +++ b/tests/Generator/Client/resource/php_content_type/MultipartException.php @@ -10,9 +10,9 @@ class MultipartException extends KnownStatusCodeException { - private array $payload; + private \Sdkgen\Client\Multipart $payload; - public function __construct(array $payload) + public function __construct(\Sdkgen\Client\Multipart $payload) { parent::__construct('The server returned an error'); @@ -20,9 +20,9 @@ public function __construct(array $payload) } /** - * @return array + * @return \Sdkgen\Client\Multipart */ - public function getPayload(): array + public function getPayload(): \Sdkgen\Client\Multipart { return $this->payload; } diff --git a/tests/Generator/Client/resource/php_test/JsonException.php b/tests/Generator/Client/resource/php_test/JsonException.php index 3bb9c36..1765d5b 100644 --- a/tests/Generator/Client/resource/php_test/JsonException.php +++ b/tests/Generator/Client/resource/php_test/JsonException.php @@ -10,9 +10,9 @@ class JsonException extends KnownStatusCodeException { - private \stdClass $payload; + private mixed $payload; - public function __construct(\stdClass $payload) + public function __construct(mixed $payload) { parent::__construct('The server returned an error'); @@ -20,9 +20,9 @@ public function __construct(\stdClass $payload) } /** - * @return \stdClass + * @return mixed */ - public function getPayload(): \stdClass + public function getPayload(): mixed { return $this->payload; } diff --git a/tests/Generator/Client/resource/php_test/MultipartException.php b/tests/Generator/Client/resource/php_test/MultipartException.php index 9bdd281..0437b35 100644 --- a/tests/Generator/Client/resource/php_test/MultipartException.php +++ b/tests/Generator/Client/resource/php_test/MultipartException.php @@ -10,9 +10,9 @@ class MultipartException extends KnownStatusCodeException { - private array $payload; + private \Sdkgen\Client\Multipart $payload; - public function __construct(array $payload) + public function __construct(\Sdkgen\Client\Multipart $payload) { parent::__construct('The server returned an error'); @@ -20,9 +20,9 @@ public function __construct(array $payload) } /** - * @return array + * @return \Sdkgen\Client\Multipart */ - public function getPayload(): array + public function getPayload(): \Sdkgen\Client\Multipart { return $this->payload; } diff --git a/tests/Generator/Client/resource/php_test/ProductTag.php b/tests/Generator/Client/resource/php_test/ProductTag.php index ac581af..46523cb 100644 --- a/tests/Generator/Client/resource/php_test/ProductTag.php +++ b/tests/Generator/Client/resource/php_test/ProductTag.php @@ -73,12 +73,12 @@ public function create(TestRequest $payload): TestResponse $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { @@ -122,12 +122,12 @@ public function update(int $id, TestRequest $payload): TestResponse $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { @@ -165,12 +165,12 @@ public function patch(int $id, TestRequest $payload): TestResponse $options = [ 'headers' => [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { @@ -252,7 +252,7 @@ public function binary(\Psr\Http\Message\StreamInterface $payload): TestResponse 'query' => $this->parser->query([ ], [ ]), - 'body' => $payload + 'body' => $payload, ]; try { @@ -300,7 +300,7 @@ public function form(array $payload): TestResponse 'query' => $this->parser->query([ ], [ ]), - 'form_params' => $payload + 'form_params' => $payload, ]; try { @@ -332,12 +332,12 @@ public function form(array $payload): TestResponse /** * Test json content type * - * @param \stdClass $payload + * @param mixed $payload * @return TestResponse * @throws JsonException * @throws ClientException */ - public function json(\stdClass $payload): TestResponse + public function json(mixed $payload): TestResponse { $url = $this->parser->url('/anything/json', [ ]); @@ -349,7 +349,7 @@ public function json(\stdClass $payload): TestResponse 'query' => $this->parser->query([ ], [ ]), - 'json' => $payload + 'json' => $payload, ]; try { @@ -380,12 +380,12 @@ public function json(\stdClass $payload): TestResponse /** * Test json content type * - * @param array $payload + * @param \Sdkgen\Client\Multipart $payload * @return TestResponse * @throws MultipartException * @throws ClientException */ - public function multipart(array $payload): TestResponse + public function multipart(\Sdkgen\Client\Multipart $payload): TestResponse { $url = $this->parser->url('/anything/multipart', [ ]); @@ -396,7 +396,7 @@ public function multipart(array $payload): TestResponse 'query' => $this->parser->query([ ], [ ]), - 'multipart' => $payload + 'multipart' => $payload->getParts(), ]; try { @@ -414,7 +414,7 @@ public function multipart(array $payload): TestResponse if ($statusCode === 500) { // @TODO currently not possible, please create an issue at https://github.com/apioo/psx-api if needed - $data = []; + $data = new \Sdkgen\Client\Multipart(); throw new MultipartException($data); } @@ -445,7 +445,7 @@ public function text(string $payload): TestResponse 'query' => $this->parser->query([ ], [ ]), - 'body' => $payload + 'body' => $payload, ]; try { @@ -493,7 +493,7 @@ public function xml(string $payload): TestResponse 'query' => $this->parser->query([ ], [ ]), - 'body' => $payload + 'body' => $payload, ]; try {