Skip to content

Commit

Permalink
fix(operation): get valid json when body is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
sidux committed Feb 27, 2024
1 parent ce8fedc commit a849bac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/Command/ExecutePlanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace APITester\Command;

use APITester\Authenticator\Exception\AuthenticationException;
use APITester\Authenticator\Exception\AuthenticationLoadingException;
use APITester\Config;
use APITester\Config\Exception\ConfigurationException;
use APITester\Definition\Loader\Exception\DefinitionLoaderNotFoundException;
Expand Down Expand Up @@ -40,9 +38,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
* @throws DefinitionLoadingException
* @throws InvalidPreparatorConfigException
* @throws RequesterNotFoundException
* @throws AuthenticationLoadingException
* @throws ConfigurationException
* @throws AuthenticationException
* @throws SuiteNotFoundException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
3 changes: 1 addition & 2 deletions src/Definition/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace APITester\Definition;

use APITester\Util\Json;
use cebe\openapi\exceptions\TypeErrorException;
use cebe\openapi\spec\Schema;
use Vural\OpenAPIFaker\Options;
Expand Down Expand Up @@ -73,7 +72,7 @@ public function getStringExample(?string $name = null): string
{
$example = $this->parent->getExample($name);

return $example->getStringBody() ?? Json::encode($this->getRandomContent());
return $example->getStringBody();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/Example/OperationExample.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,10 @@ public function setPath(?string $path): self
return $this;
}

public function getStringBody(): ?string
public function getStringBody(): string
{
if ($this->getBody() === null) {
return null;
return '{}';
}

return $this->getBody()
Expand Down
15 changes: 6 additions & 9 deletions src/Test/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class Plan
'ignore-baseline',
'only-baseline',
'part',
'operation-id',
];

private readonly Authenticator $authenticator;
Expand Down Expand Up @@ -100,8 +101,6 @@ public function __construct(
* @throws DefinitionLoadingException
* @throws RequesterNotFoundException
* @throws InvalidPreparatorConfigException
* @throws AuthenticationLoadingException
* @throws AuthenticationException
* @throws SuiteNotFoundException
*/
public function execute(
Expand Down Expand Up @@ -187,8 +186,6 @@ private function resetBaseLine(Config\Suite $suiteConfig): void
/**
* @param array<string, mixed> $options
*
* @throws AuthenticationException
* @throws AuthenticationLoadingException
* @throws DefinitionLoaderNotFoundException
* @throws DefinitionLoadingException
* @throws InvalidPreparatorConfigException
Expand Down Expand Up @@ -343,15 +340,15 @@ private function loadRequester(string $name, string $baseUri, ?HttpKernelInterfa
throw new RequesterNotFoundException($name);
}

/**
* @throws AuthenticationLoadingException
* @throws AuthenticationException
*/
private function authenticate(Config\Suite $config, Api $api, Requester $requester): Tokens
{
$tokens = new Tokens();
foreach ($config->getAuthentications() as $authConf) {
$tokens->add($this->authenticator->authenticate($authConf, $api, $requester));
try {
$tokens->add($this->authenticator->authenticate($authConf, $api, $requester));
} catch (AuthenticationException|AuthenticationLoadingException $e) {
$this->logger->error($e->getMessage());
}
}

return $tokens;
Expand Down

0 comments on commit a849bac

Please sign in to comment.