Skip to content

Commit

Permalink
use multipart
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Sep 22, 2024
1 parent 7025b9c commit 77930ae
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 65 deletions.
12 changes: 6 additions & 6 deletions src/Generator/Client/Language/php-operation.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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 %}
];
Expand Down Expand Up @@ -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 %}
Expand Down
12 changes: 6 additions & 6 deletions tests/Generator/Client/resource/php/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tests/Generator/Client/resource/php_collection/BarTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tests/Generator/Client/resource/php_collection/FooBarTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions tests/Generator/Client/resource/php_collection/FooBazTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 14 additions & 14 deletions tests/Generator/Client/resource/php_content_type/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function binary(\Psr\Http\Message\StreamInterface $body): \Psr\Http\Messa
'query' => $this->parser->query([
], [
]),
'body' => $body
'body' => $body,
];

try {
Expand Down Expand Up @@ -81,7 +81,7 @@ public function form(array $body): array
'query' => $this->parser->query([
], [
]),
'form_params' => $body
'form_params' => $body,
];

try {
Expand Down Expand Up @@ -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', [
]);
Expand All @@ -129,7 +129,7 @@ public function json(\stdClass $body): \stdClass
'query' => $this->parser->query([
], [
]),
'json' => $body
'json' => $body,
];

try {
Expand Down Expand Up @@ -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', [
]);
Expand All @@ -174,15 +174,15 @@ public function multipart(array $body): array
'query' => $this->parser->query([
], [
]),
'multipart' => $body
'multipart' => $body->getParts(),
];

try {
$response = $this->httpClient->request('POST', $url, $options);
$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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public function text(string $body): string
'query' => $this->parser->query([
], [
]),
'body' => $body
'body' => $body,
];

try {
Expand Down Expand Up @@ -268,7 +268,7 @@ public function xml(string $body): string
'query' => $this->parser->query([
], [
]),
'body' => $body
'body' => $body,
];

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

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');

$this->payload = $payload;
}

/**
* @return \stdClass
* @return mixed
*/
public function getPayload(): \stdClass
public function getPayload(): mixed
{
return $this->payload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

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');

$this->payload = $payload;
}

/**
* @return array
* @return \Sdkgen\Client\Multipart
*/
public function getPayload(): array
public function getPayload(): \Sdkgen\Client\Multipart
{
return $this->payload;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Generator/Client/resource/php_test/JsonException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

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');

$this->payload = $payload;
}

/**
* @return \stdClass
* @return mixed
*/
public function getPayload(): \stdClass
public function getPayload(): mixed
{
return $this->payload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

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');

$this->payload = $payload;
}

/**
* @return array
* @return \Sdkgen\Client\Multipart
*/
public function getPayload(): array
public function getPayload(): \Sdkgen\Client\Multipart
{
return $this->payload;
}
Expand Down
Loading

0 comments on commit 77930ae

Please sign in to comment.