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;
/** @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;
}
/**

View File

@ -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;

View File

@ -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

View File

@ -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
*/