Compare commits

...

3 Commits

Author SHA1 Message Date
c6963e0574 Merge pull request 'v1.4.1' (#13) from dev into master
Reviewed-on: #13
2023-09-10 07:59:00 +00:00
5c85f23514
Bump version 2023-09-10 15:58:31 +08:00
35e1984326
JSON body & header was fixed 2023-09-10 15:57:39 +08:00
4 changed files with 20 additions and 19 deletions

View File

@ -132,19 +132,19 @@ abstract class AbstractConverter implements ConverterContract
{ {
$request_class = static::REQUEST_CLASS; $request_class = static::REQUEST_CLASS;
/** @var RequestContract $result */ /** @var RequestContract $request */
$result = new $request_class(); $request = new $request_class();
$result->setName($item->name); $request->setName($item->name);
$result->setHttpVersion(1.1); //TODO http version? $request->setHttpVersion(1.1); //TODO http version?
$result->setDescription($item->request?->description ?? null); $request->setDescription($item->request?->description ?? null);
$result->setVerb($item->request->method); $request->setVerb($item->request->method);
$result->setUrl($item->request->url->raw); $request->setUrl($item->request->url->raw);
$result->setHeaders($item->request->header); $request->setHeaders($item->request->header);
$result->setAuth($item->request?->auth ?? $this->collection?->auth ?? null); $request->setAuth($item->request?->auth ?? $this->collection?->auth ?? null);
if ($item->request->method !== 'GET' && !empty($item->request->body)) { if ($item->request->method !== 'GET' && !empty($item->request->body)) {
$result->setBody($item->request->body); $request->setBody($item->request->body);
} }
return $result; return $request;
} }
/** /**

View File

@ -219,11 +219,12 @@ abstract class AbstractRequest implements Stringable, RequestContract
{ {
$this->setBodymode($body->mode); $this->setBodymode($body->mode);
if ($body->mode === 'formdata') { if ($body->mode === 'formdata') {
$this->setHeader('Content-Type', 'multipart/form-data') $this->setHeader('Content-Type', 'multipart/form-data')->setFormdataBody($body);
->setFormdataBody($body); } elseif ($body->mode === 'raw') {
} elseif (!empty($body->options) && $body->options->{$this->bodymode}->language === 'json') { $this->setBodyAsIs($body);
$this->setHeader('Content-Type', 'application/json') if (!empty($body->options) && $body->options->{$this->bodymode}->language === 'json') {
->setJsonBody($body); $this->setHeader('Content-Type', 'application/json');
}
} }
return $this; return $this;
} }
@ -251,7 +252,7 @@ abstract class AbstractRequest implements Stringable, RequestContract
* @param object $body * @param object $body
* @return $this * @return $this
*/ */
protected function setJsonBody(object $body): static protected function setBodyAsIs(object $body): static
{ {
$this->body = $body->{$this->getBodymode()}; $this->body = $body->{$this->getBodymode()};
return $this; return $this;

View File

@ -21,7 +21,7 @@ class Processor
/** /**
* Converter version * Converter version
*/ */
public const VERSION = '1.4.0'; public const VERSION = '1.4.1';
/** /**
* @var string[] Paths to collection files * @var string[] Paths to collection files

View File

@ -215,7 +215,7 @@ class AbstractRequestTest extends TestCase
* @covers PmConverter\Converters\Abstract\AbstractRequest::setBodymode() * @covers PmConverter\Converters\Abstract\AbstractRequest::setBodymode()
* @covers PmConverter\Converters\Abstract\AbstractRequest::setHeader() * @covers PmConverter\Converters\Abstract\AbstractRequest::setHeader()
* @covers PmConverter\Converters\Abstract\AbstractRequest::setBody() * @covers PmConverter\Converters\Abstract\AbstractRequest::setBody()
* @covers PmConverter\Converters\Abstract\AbstractRequest::setJsonBody() * @covers PmConverter\Converters\Abstract\AbstractRequest::setBodyAsIs()
* @covers PmConverter\Converters\Abstract\AbstractRequest::getBody() * @covers PmConverter\Converters\Abstract\AbstractRequest::getBody()
* @return void * @return void
*/ */