Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 25 additions & 78 deletions devenv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1708326833,
"narHash": "sha256-cihQPArrJhDU1jqqKDeyI91ZK62lUlGXYNncz2k9mjk=",
"lastModified": 1736426010,
"owner": "cachix",
"repo": "devenv",
"rev": "bc4602a41c197edd5838c8a97da2ed0c1fc75d0e",
"rev": "1c384bc4be3ee571511fbbc6fdc94fe47d60f6cf",
"type": "github"
},
"original": {
Expand All @@ -20,11 +19,10 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"lastModified": 1733328505,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"type": "github"
},
"original": {
Expand All @@ -33,37 +31,39 @@
"type": "github"
}
},
"flake-utils": {
"git-hooks": {
"inputs": {
"systems": "systems"
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"lastModified": 1735882644,
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "a5a961387e75ae44cc20f0a57ae463da5e959656",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"git-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1703887061,
"narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=",
"lastModified": 1709087332,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
Expand All @@ -74,11 +74,10 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1708247094,
"narHash": "sha256-H2VS7VwesetGDtIaaz4AMsRkPoSLEVzL/Ika8gnbUnE=",
"lastModified": 1736848588,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "045b51a3ae66f673ed44b5bbd1f4a341d96703bf",
"rev": "357cd3dfdb8993af11268d755d53357720675e66",
"type": "github"
},
"original": {
Expand All @@ -88,66 +87,14 @@
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1704874635,
"narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1708018599,
"narHash": "sha256-M+Ng6+SePmA8g06CmUZWi1AjG2tFBX9WCXElBHEKnyM=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "5df5a70ad7575f6601d91f0efec95dd9bc619431",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"git-hooks": "git-hooks",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
"pre-commit-hooks": [
"git-hooks"
]
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/Definition/Loader/OpenApiDefinitionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,10 @@ private function extractDeepExamples(Schema $schema, bool $optional = false, str

if (isset($schema->type)) {
if ($schema->type === 'array' && $schema->items instanceof Schema) {
if ($schema->example !== null) {
return $schema->example;
}

return [
$this->extractDeepExamples($schema->items, false, $path),
];
Expand Down
5 changes: 5 additions & 0 deletions src/Preparator/Config/PreparatorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class PreparatorConfig

public ResponseConfig $response;

/**
* @var array<string, string>
*/
public array $headers = [];

public function __construct()
{
$this->response = new ResponseConfig();
Expand Down
2 changes: 2 additions & 0 deletions src/Preparator/TestCasesPreparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ final public function buildTestCase(
$example->setAuthenticationHeaders($this->tokens);
}

$example->setHeaders($this->config->headers);

return new TestCase(
static::getName()
. ' - '
Expand Down
60 changes: 60 additions & 0 deletions src/Requester/HttpDumpRequester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace APITester\Requester;

use APITester\Util\Json;
use Nyholm\Psr7\Response;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

final class HttpDumpRequester extends Requester
{
/**
* @var ResponseInterface[]
*/
private array $responses = [];

public function request(RequestInterface $request, string $id): void
{
$httpDump = $this->requestToHttp($request, $id);

echo "\n" . $httpDump . "\n";

$response = new Response($request->getMethod() === 'POST' ? 201 : 200);
$this->responses[$id] = $response;
}

public function getResponse(string $id): ResponseInterface
{
return $this->responses[$id];
}

public static function getName(): string
{
return 'http-dump';
}

private function requestToHttp(RequestInterface $request, string $requestName): string
{
$dump = "###\n";
$dump .= $request->getMethod() . ' ' . '{{url}}' . $request->getUri() . "\n";

foreach ($request->getHeaders() as $name => $values) {
foreach ($values as $value) {
$dump .= "{$name}: {$value}\n";
}
}

$body = (string) $request->getBody();
if (!empty($body)) {
if (Json::isJson($body)) {
$body = Json::prettify($body);
}
$dump .= "\n" . $body . "\n";
}

return $dump;
}
}
2 changes: 0 additions & 2 deletions src/Requester/Requester.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ abstract public function request(RequestInterface $request, string $id): void;

abstract public function getResponse(string $id): ResponseInterface;

abstract public function setBaseUri(string $baseUri): void;

protected function fillRequestVars(RequestInterface $request): void
{
foreach ($request->getHeaders() as $name => $header) {
Expand Down
2 changes: 1 addition & 1 deletion src/Test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct(
$this->id = Random::id('testcase_');
$this->excludedFields = array_unique([...$this->excludedFields, ...$excludedFields]);
$nameParts = explode(' - ', $name);
$this->preparator = $nameParts[0] ?? null;
$this->preparator = $nameParts[0] ?? '';
$this->operation = $nameParts[1] ?? null;
$this->request = $operationExample->getPsrRequest();
$this->schemaValidation = $schemaValidation;
Expand Down
Loading