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
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
},
"require": {
"php": "^8.4.0",
"symfony/yaml": "^6 || ^7",
"symfony/yaml": "^7.4.12 || ^8.0.12",
"devizzent/cebe-php-openapi": "^1.1.5"
},
"require-dev": {
"phpunit/phpunit": "^12.5.11",
"phpstan/phpstan": "^1.12.33",
"phpunit/phpunit": "^13.1.11",
"phpstan/phpstan": "^2.1.55",
"squizlabs/php_codesniffer": "^4.0.1",
"mikey179/vfsstream": "^v1.6.12",
"infection/infection": "^0.32.6"
"infection/infection": "^0.33.2"
},
"config": {
"allow-plugins": {
Expand Down
1 change: 1 addition & 0 deletions src/CebeReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(
if (empty($this->supportedVersions)) {
throw CannotSupport::noSupportedVersions();
}
/** @phpstan-ignore-next-line this enforces the constructor type hint*/
(fn (OpenAPIVersion ...$versions) => null)(...$this->supportedVersions);
}

Expand Down
12 changes: 4 additions & 8 deletions src/ValueObject/Valid/V30/Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function __construct(
}
}

/** @return string[] */
/** @return list<string> */
public function typesItCanBe(): array
{
$possibilities = [array_merge(
Expand Down Expand Up @@ -179,10 +179,6 @@ private function validateTypes(
null|string|array $type,
bool $nullable,
): array {
if (isset($this->types)) {
return $this->types;
}

if (empty($type)) { // If type is unspecified, nullable has no effect
return []; // So we can return immediately
}
Expand All @@ -207,12 +203,12 @@ private function validateTypes(
$result[] = Type::Null;
}

return $result;
return array_values($result);
}

/**
* @param list<Type> $types
* @param list<Value>|null $enum
* @param array<Value>|null $enum
* @return non-empty-list<Value>
*/
private function reviewEnum(
Expand Down Expand Up @@ -382,7 +378,7 @@ private function validateRequired(array | null $required): array
$this->addWarning('required must not contain duplicates', Warning::INVALID);
}

return $uniqueRequired;
return array_values($uniqueRequired);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/ValueObject/Valid/V30/OpenAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class OpenAPI extends Validated
{
/**
* @param array<int, Server> $servers
* @param list<Server> $servers
* Optional, may be left empty.
* If empty or unspecified, the array will contain the default Server.
* The default Server has "url" === "/" and no "variables"
Expand Down Expand Up @@ -62,7 +62,7 @@ public static function fromPartial(Partial\OpenAPI $openAPI): self

/**
* @param Partial\Server[] $servers
* @return array<int,Server>
* @return list<Server>
*/
private static function validateServers(
Identifier $identifier,
Expand Down Expand Up @@ -93,7 +93,7 @@ private function reviewServers(array $servers): void
}

/**
* @param Server[] $servers
* @param list<Server> $servers
* @param null|Partial\PathItem[] $pathItems
* @return array<string,PathItem>
*/
Expand Down
8 changes: 4 additions & 4 deletions src/ValueObject/Valid/V30/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class Operation extends Validated
{
/**
* @param array<int,Server> $servers
* @param list<Server> $servers
* Optional, may be left empty.
* If empty or unspecified, the array will contain the Path level servers
*
Expand Down Expand Up @@ -57,7 +57,7 @@ public function withoutServers(): Operation
}

/**
* @param Server[] $pathServers
* @param list<Server> $pathServers
* @param Parameter[] $pathParameters
*/
public static function fromPartial(
Expand Down Expand Up @@ -104,9 +104,9 @@ public static function fromPartial(
}

/**
* @param array<int,Server> $pathServers
* @param list<Server> $pathServers
* @param Partial\Server[] $operationServers
* @return array<int,Server>>
* @return list<Server>
*/
private static function validateServers(
Identifier $identifier,
Expand Down
10 changes: 5 additions & 5 deletions src/ValueObject/Valid/V30/PathItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
final class PathItem extends Validated
{
/**
* @param array<int,Server> $servers
* @param list<Server> $servers
*
* @param array<int,Parameter> $parameters
* The list MUST NOT include duplicated parameters.
Expand Down Expand Up @@ -62,7 +62,7 @@ public function withoutServers(): PathItem
}

/**
* @param array<int,Server> $openAPIServers
* @param list<Server> $openAPIServers
* If the pathItem does not contain servers, this will be used instead
*/
public static function fromPartial(
Expand Down Expand Up @@ -168,15 +168,15 @@ public function getOperations(): array
/**
* @param array<int,Server> $openAPIServers
* @param Partial\Server[] $pathServers
* @return array<int,Server>>
* @return list<Server>
*/
private static function validateServers(
Identifier $identifier,
array $openAPIServers,
array $pathServers
): array {
if (empty($pathServers)) {
return $openAPIServers;
return array_values($openAPIServers);
}

return array_values(array_map(
Expand Down Expand Up @@ -249,7 +249,7 @@ private function reviewParameters(array $parameters): void
}

/**
* @param Server[] $servers
* @param list<Server> $servers
* @param Parameter[] $parameters
*/
private static function validateOperation(
Expand Down
4 changes: 2 additions & 2 deletions src/ValueObject/Valid/V30/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function canBePrimitive(): bool
public function typesItCanBe(): array
{
if ($this->value === true) {
return [
return array_values([
Type::Null->value,
...Type::valuesForVersion(OpenAPIVersion::Version_3_0),
];
]);
} elseif ($this->value === false) {
return [];
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/ValueObject/Valid/V30/ServerVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function __construct(
}
}

$this->enum = $serverVariable->enum;
$this->enum = isset($serverVariable->enum)
? array_values($serverVariable->enum)
: null;
}
}
10 changes: 5 additions & 5 deletions src/ValueObject/Valid/V31/Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function __construct(
}
}

/** @return string[] */
/** @return list<string> */
public function typesItCanBe(): array
{
$possibilities = [array_merge(
Expand Down Expand Up @@ -175,16 +175,16 @@ private function validateTypes(null|string|array $type): array
$type = [$type];
}

return array_map(
return array_values(array_map(
fn($t) => Type::tryFromVersion(OpenAPIVersion::Version_3_1, $t)
?? throw InvalidOpenAPI::invalidType($this->getIdentifier(), $t),
$type,
);
));
}

/**
* @param list<Type> $types
* @param list<Value>|null $enum
* @param array<Value>|null $enum
* @return non-empty-list<Value>|null
*/
private function reviewEnum(
Expand Down Expand Up @@ -404,7 +404,7 @@ private function validateRequired(array | null $required): array
$this->addWarning('required must not contain duplicates', Warning::INVALID);
}

return $uniqueRequired;
return array_values($uniqueRequired);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ValueObject/Valid/V31/OpenAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
final class OpenAPI extends Validated
{
/**
* @param array<int, Server> $servers
* @param list<Server> $servers
* Optional, may be left empty.
* If empty or unspecified, the array will contain the default Server.
* The default Server has "url" === "/" and no "variables"
Expand Down Expand Up @@ -62,7 +62,7 @@ public static function fromPartial(Partial\OpenAPI $openAPI): self

/**
* @param Partial\Server[] $servers
* @return array<int,Server>
* @return list<Server>
*/
private static function validateServers(
Identifier $identifier,
Expand Down
6 changes: 3 additions & 3 deletions src/ValueObject/Valid/V31/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
final class Operation extends Validated
{
/**
* @param array<int,Server> $servers
* @param list<Server> $servers
* Optional, may be left empty.
* If empty or unspecified, the array will contain the Path level servers
*
Expand Down Expand Up @@ -106,15 +106,15 @@ public static function fromPartial(
/**
* @param array<int,Server> $pathServers
* @param Partial\Server[] $operationServers
* @return array<int,Server>>
* @return list<Server>
*/
private static function validateServers(
Identifier $identifier,
array $pathServers,
array $operationServers
): array {
if (empty($operationServers)) {
return $pathServers;
return array_values($pathServers);
}

$result = array_values(array_map(
Expand Down
6 changes: 3 additions & 3 deletions src/ValueObject/Valid/V31/PathItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
final class PathItem extends Validated
{
/**
* @param array<int,Server> $servers
* @param list<Server> $servers
*
* @param array<int,Parameter> $parameters
* The list MUST NOT include duplicated parameters.
Expand Down Expand Up @@ -168,15 +168,15 @@ public function getOperations(): array
/**
* @param array<int,Server> $openAPIServers
* @param Partial\Server[] $pathServers
* @return array<int,Server>>
* @return list<Server>
*/
private static function validateServers(
Identifier $identifier,
array $openAPIServers,
array $pathServers
): array {
if (empty($pathServers)) {
return $openAPIServers;
return array_values($openAPIServers);
}

return array_values(array_map(
Expand Down
4 changes: 2 additions & 2 deletions src/ValueObject/Valid/V31/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function canBePrimitive(): bool
public function typesItCanBe(): array
{
if ($this->value === true) {
return [
return array_values([
Type::Null->value,
...Type::valuesForVersion(OpenAPIVersion::Version_3_0),
];
]);
} elseif ($this->value === false) {
return [];
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/ValueObject/Valid/V31/ServerVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function __construct(
}
}

$this->enum = $serverVariable->enum;
$this->enum = array_values($serverVariable->enum ?? []);
}
}