diff --git a/src/Definition/Operation.php b/src/Definition/Operation.php index b5f406b..8c9de33 100644 --- a/src/Definition/Operation.php +++ b/src/Definition/Operation.php @@ -419,12 +419,12 @@ public function setParametersIn(Parameters $parameters, string $in): self return $this; } - public function getExample(?string $name = null): OperationExample + public function getExample(?string $name = null, mixed $default = null): OperationExample { $examples = $this->getExamples(); if ($name !== null) { return $examples - ->get($name) + ->get($name, $default) ; } diff --git a/src/Preparator/Error404Preparator.php b/src/Preparator/Error404Preparator.php index 08302be..5a6209a 100644 --- a/src/Preparator/Error404Preparator.php +++ b/src/Preparator/Error404Preparator.php @@ -40,23 +40,13 @@ private function prepareTestCase(DefinitionResponse $response): array $testcases = []; - if ($operation->getRequestBodies()->count() === 0) { - $testcases[] = $this->buildTestCase( - OperationExample::create('RandomPath', $operation) - ->setForceRandom() - ->setResponse( - ResponseExample::create() - ->setStatusCode($this->config->response->getStatusCode() ?? '404') - ->setHeaders($this->config->response->headers ?? []) - ->setContent($this->config->response->body ?? $response->getDescription()) - ) + foreach (range(1, $operation->getRequestBodies()->count() ?: 1) as $ignored) { + $notFoundExample = $operation->getExample( + '404', + OperationExample::create('RandomPath', $operation)->setForceRandom() ); - } - - foreach ($operation->getRequestBodies() as $ignored) { $testcases[] = $this->buildTestCase( - OperationExample::create('RandomPath', $operation) - ->setForceRandom() + $notFoundExample ->setResponse( ResponseExample::create() ->setStatusCode($this->config->response->getStatusCode() ?? '404')