Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/Schema/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class Parameter
public const IN_HEADER = 'header';
public const IN_PATH = 'path';
public const IN_QUERY = 'query';
public const IN_QUERYSTRING = 'querystring';

public const INS = [
self::IN_COOKIE,
self::IN_HEADER,
self::IN_PATH,
self::IN_QUERY,
self::IN_QUERYSTRING,
];

private string $name;
Expand Down
2 changes: 2 additions & 0 deletions src/Schema/PathItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PathItem
public const OPERATION_HEAD = 'head';
public const OPERATION_PATCH = 'patch';
public const OPERATION_TRACE = 'trace';
public const OPERATION_QUERY = 'query';

/** @var string[] */
private static array $allowedOperations = [
Expand All @@ -24,6 +25,7 @@ class PathItem
self::OPERATION_HEAD,
self::OPERATION_PATCH,
self::OPERATION_TRACE,
self::OPERATION_QUERY,
];

private ?string $summary = null;
Expand Down
18 changes: 17 additions & 1 deletion tests/Cases/Schema/ParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,27 @@ public function testContent(): void
Assert::same($expectedData, $parameter->toArray());
}

public function testQuerystringLocation(): void
{
$expectedData = [
'name' => 'query',
'in' => 'querystring',
'content' => [
'application/x-www-form-urlencoded' => ['schema' => ['type' => 'string']],
],
];

$parameter = Parameter::fromArray($expectedData);

Assert::same(Parameter::IN_QUERYSTRING, $parameter->getIn());
Assert::same($expectedData, $parameter->toArray());
}

public function testInvalidIn(): void
{
Assert::exception(static function (): void {
new Parameter('foo', 'invalid');
}, InvalidArgumentException::class, 'Invalid value "invalid" for attribute "in" given. It must be one of "cookie, header, path, query".');
}, InvalidArgumentException::class, 'Invalid value "invalid" for attribute "in" given. It must be one of "cookie, header, path, query, querystring".');
}

public function testSchemaReference(): void
Expand Down
38 changes: 38 additions & 0 deletions tests/Cases/Schema/PathItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types = 1);

namespace Tests\Cases\Schema;

require_once __DIR__ . '/../../bootstrap.php';

use Contributte\OpenApi\Schema\PathItem;
use Tester\Assert;
use Tester\TestCase;

class PathItemTest extends TestCase
{

private const RESPONSES = ['responses' => ['200' => ['description' => 'Success']]];

public function testOperations(): void
{
$expectedData = [
'get' => self::RESPONSES,
'post' => self::RESPONSES,
];

Assert::same($expectedData, PathItem::fromArray($expectedData)->toArray());
}

public function testQueryOperation(): void
{
$expectedData = [
'get' => self::RESPONSES,
'query' => self::RESPONSES,
];

Assert::same($expectedData, PathItem::fromArray($expectedData)->toArray());
}

}

(new PathItemTest())->run();