From 35e198432647a8c01de062db4c92103d425da0f2 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Sun, 10 Sep 2023 15:57:39 +0800 Subject: [PATCH 1/2] JSON body & header was fixed --- src/Converters/Abstract/AbstractConverter.php | 22 +++++++++---------- src/Converters/Abstract/AbstractRequest.php | 13 ++++++----- tests/AbstractRequestTest.php | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Converters/Abstract/AbstractConverter.php b/src/Converters/Abstract/AbstractConverter.php index d049fe1..419a801 100644 --- a/src/Converters/Abstract/AbstractConverter.php +++ b/src/Converters/Abstract/AbstractConverter.php @@ -132,19 +132,19 @@ abstract class AbstractConverter implements ConverterContract { $request_class = static::REQUEST_CLASS; - /** @var RequestContract $result */ - $result = new $request_class(); - $result->setName($item->name); - $result->setHttpVersion(1.1); //TODO http version? - $result->setDescription($item->request?->description ?? null); - $result->setVerb($item->request->method); - $result->setUrl($item->request->url->raw); - $result->setHeaders($item->request->header); - $result->setAuth($item->request?->auth ?? $this->collection?->auth ?? null); + /** @var RequestContract $request */ + $request = new $request_class(); + $request->setName($item->name); + $request->setHttpVersion(1.1); //TODO http version? + $request->setDescription($item->request?->description ?? null); + $request->setVerb($item->request->method); + $request->setUrl($item->request->url->raw); + $request->setHeaders($item->request->header); + $request->setAuth($item->request?->auth ?? $this->collection?->auth ?? null); if ($item->request->method !== 'GET' && !empty($item->request->body)) { - $result->setBody($item->request->body); + $request->setBody($item->request->body); } - return $result; + return $request; } /** diff --git a/src/Converters/Abstract/AbstractRequest.php b/src/Converters/Abstract/AbstractRequest.php index f87b6a4..858123e 100644 --- a/src/Converters/Abstract/AbstractRequest.php +++ b/src/Converters/Abstract/AbstractRequest.php @@ -219,11 +219,12 @@ abstract class AbstractRequest implements Stringable, RequestContract { $this->setBodymode($body->mode); if ($body->mode === 'formdata') { - $this->setHeader('Content-Type', 'multipart/form-data') - ->setFormdataBody($body); - } elseif (!empty($body->options) && $body->options->{$this->bodymode}->language === 'json') { - $this->setHeader('Content-Type', 'application/json') - ->setJsonBody($body); + $this->setHeader('Content-Type', 'multipart/form-data')->setFormdataBody($body); + } elseif ($body->mode === 'raw') { + $this->setBodyAsIs($body); + if (!empty($body->options) && $body->options->{$this->bodymode}->language === 'json') { + $this->setHeader('Content-Type', 'application/json'); + } } return $this; } @@ -251,7 +252,7 @@ abstract class AbstractRequest implements Stringable, RequestContract * @param object $body * @return $this */ - protected function setJsonBody(object $body): static + protected function setBodyAsIs(object $body): static { $this->body = $body->{$this->getBodymode()}; return $this; diff --git a/tests/AbstractRequestTest.php b/tests/AbstractRequestTest.php index c460e56..89491fe 100644 --- a/tests/AbstractRequestTest.php +++ b/tests/AbstractRequestTest.php @@ -215,7 +215,7 @@ class AbstractRequestTest extends TestCase * @covers PmConverter\Converters\Abstract\AbstractRequest::setBodymode() * @covers PmConverter\Converters\Abstract\AbstractRequest::setHeader() * @covers PmConverter\Converters\Abstract\AbstractRequest::setBody() - * @covers PmConverter\Converters\Abstract\AbstractRequest::setJsonBody() + * @covers PmConverter\Converters\Abstract\AbstractRequest::setBodyAsIs() * @covers PmConverter\Converters\Abstract\AbstractRequest::getBody() * @return void */ -- 2.46.GIT From 5c85f235141fea9fa48b4e280afa64c7bc81998a Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Sun, 10 Sep 2023 15:58:31 +0800 Subject: [PATCH 2/2] Bump version --- src/Processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Processor.php b/src/Processor.php index c6d328a..c74f2e5 100644 --- a/src/Processor.php +++ b/src/Processor.php @@ -21,7 +21,7 @@ class Processor /** * Converter version */ - public const VERSION = '1.4.0'; + public const VERSION = '1.4.1'; /** * @var string[] Paths to collection files -- 2.46.GIT