From 9051093f1ac299f4b0feab648fa4a8cbc98a6f07 Mon Sep 17 00:00:00 2001 From: Christoph Kappestein Date: Sun, 22 Sep 2024 10:49:26 +0200 Subject: [PATCH] ignore set explicit content type for multipart --- .../Client/Language/php-operation.php.twig | 3 +- .../Language/typescript-operation.ts.twig | 3 +- .../resource/php_content_type/Client.php | 1 - .../Client/resource/php_test/ProductTag.php | 1 - .../Client/resource/php_test/TestResponse.php | 30 +++++++++++++++++++ .../typescript_content_type/Client.ts | 1 - .../resource/typescript_test/ProductTag.ts | 1 - .../resource/typescript_test/TestResponse.ts | 3 ++ 8 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/Generator/Client/Language/php-operation.php.twig b/src/Generator/Client/Language/php-operation.php.twig index 033bd125..cbb99312 100644 --- a/src/Generator/Client/Language/php-operation.php.twig +++ b/src/Generator/Client/Language/php-operation.php.twig @@ -22,7 +22,8 @@ $options = [ 'headers' => [ -{% if operation.bodyContentType %} +{% if operation.bodyContentShape == 'multipart/form-data' %} +{% elseif operation.bodyContentType %} 'Content-Type' => '{{ operation.bodyContentType }}', {% elseif operation.bodyName %} 'Content-Type' => 'application/json' diff --git a/src/Generator/Client/Language/typescript-operation.ts.twig b/src/Generator/Client/Language/typescript-operation.ts.twig index 81ea6490..90f23c26 100644 --- a/src/Generator/Client/Language/typescript-operation.ts.twig +++ b/src/Generator/Client/Language/typescript-operation.ts.twig @@ -21,7 +21,8 @@ url: url, method: '{{ operation.method }}', headers: { -{% if operation.bodyContentType %} +{% if operation.bodyContentShape == 'multipart/form-data' %} +{% elseif operation.bodyContentType %} 'Content-Type': '{{ operation.bodyContentType }}', {% elseif operation.bodyName %} 'Content-Type': 'application/json', diff --git a/tests/Generator/Client/resource/php_content_type/Client.php b/tests/Generator/Client/resource/php_content_type/Client.php index a1e0ef93..02f31359 100644 --- a/tests/Generator/Client/resource/php_content_type/Client.php +++ b/tests/Generator/Client/resource/php_content_type/Client.php @@ -170,7 +170,6 @@ public function multipart(array $body): array $options = [ 'headers' => [ - 'Content-Type' => 'multipart/form-data', ], 'query' => $this->parser->query([ ], [ diff --git a/tests/Generator/Client/resource/php_test/ProductTag.php b/tests/Generator/Client/resource/php_test/ProductTag.php index 8586f516..3ab4cc77 100644 --- a/tests/Generator/Client/resource/php_test/ProductTag.php +++ b/tests/Generator/Client/resource/php_test/ProductTag.php @@ -362,7 +362,6 @@ public function multipart(array $payload): TestResponse $options = [ 'headers' => [ - 'Content-Type' => 'multipart/form-data', ], 'query' => $this->parser->query([ ], [ diff --git a/tests/Generator/Client/resource/php_test/TestResponse.php b/tests/Generator/Client/resource/php_test/TestResponse.php index 2fa349b5..76afaa5e 100644 --- a/tests/Generator/Client/resource/php_test/TestResponse.php +++ b/tests/Generator/Client/resource/php_test/TestResponse.php @@ -10,6 +10,9 @@ class TestResponse implements \JsonSerializable, \PSX\Record\RecordableInterface { protected ?TestMapScalar $args = null; + protected ?string $data = null; + protected ?TestMapScalar $files = null; + protected ?TestMapScalar $form = null; protected ?TestMapScalar $headers = null; protected ?TestRequest $json = null; protected ?string $method = null; @@ -21,6 +24,30 @@ public function getArgs() : ?TestMapScalar { return $this->args; } + public function setData(?string $data) : void + { + $this->data = $data; + } + public function getData() : ?string + { + return $this->data; + } + public function setFiles(?TestMapScalar $files) : void + { + $this->files = $files; + } + public function getFiles() : ?TestMapScalar + { + return $this->files; + } + public function setForm(?TestMapScalar $form) : void + { + $this->form = $form; + } + public function getForm() : ?TestMapScalar + { + return $this->form; + } public function setHeaders(?TestMapScalar $headers) : void { $this->headers = $headers; @@ -50,6 +77,9 @@ public function toRecord() : \PSX\Record\RecordInterface /** @var \PSX\Record\Record $record */ $record = new \PSX\Record\Record(); $record->put('args', $this->args); + $record->put('data', $this->data); + $record->put('files', $this->files); + $record->put('form', $this->form); $record->put('headers', $this->headers); $record->put('json', $this->json); $record->put('method', $this->method); diff --git a/tests/Generator/Client/resource/typescript_content_type/Client.ts b/tests/Generator/Client/resource/typescript_content_type/Client.ts index aebd6e8c..1e68e09b 100644 --- a/tests/Generator/Client/resource/typescript_content_type/Client.ts +++ b/tests/Generator/Client/resource/typescript_content_type/Client.ts @@ -154,7 +154,6 @@ export class Client extends ClientAbstract { url: url, method: 'POST', headers: { - 'Content-Type': 'multipart/form-data', }, params: this.parser.query({ }, [ diff --git a/tests/Generator/Client/resource/typescript_test/ProductTag.ts b/tests/Generator/Client/resource/typescript_test/ProductTag.ts index 84dfae38..c657309a 100644 --- a/tests/Generator/Client/resource/typescript_test/ProductTag.ts +++ b/tests/Generator/Client/resource/typescript_test/ProductTag.ts @@ -331,7 +331,6 @@ export class ProductTag extends TagAbstract { url: url, method: 'POST', headers: { - 'Content-Type': 'multipart/form-data', }, params: this.parser.query({ }, [ diff --git a/tests/Generator/Client/resource/typescript_test/TestResponse.ts b/tests/Generator/Client/resource/typescript_test/TestResponse.ts index 62e0f557..f560e249 100644 --- a/tests/Generator/Client/resource/typescript_test/TestResponse.ts +++ b/tests/Generator/Client/resource/typescript_test/TestResponse.ts @@ -7,6 +7,9 @@ import {TestMapScalar} from "./TestMapScalar"; import {TestRequest} from "./TestRequest"; export interface TestResponse { args?: TestMapScalar + data?: string + files?: TestMapScalar + form?: TestMapScalar headers?: TestMapScalar json?: TestRequest method?: string