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
2 changes: 1 addition & 1 deletion src/Parser/Schema/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private function enumKeys(array $data, string $location, array $enum): array
}

$keys = Value::stringList($data['x-enum-keys'], "{$location}/x-enum-keys");
if (count($keys) !== count($enum)) {
if ($keys !== [] && count($keys) !== count($enum)) {
throw new InvalidSpecification("Expected x-enum-keys to match enum length at {$location}");
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Schema/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ public function test_enum_metadata_is_preserved_for_openapi_two_inline_parameter
self::assertSame(['NetworkRequests'], $schema->enumKeys);
}

public function test_empty_enum_keys_use_derived_names(): void
{
$schema = $this->reader(Version::V3_0)->read([
'type' => 'string',
'enum' => ['first', 'second'],
'x-enum-keys' => [],
], '#/x');

self::assertInstanceOf(StringSchema::class, $schema);
self::assertSame([], $schema->enumKeys);
}

public function test_enum_keys_must_match_enum_length(): void
{
$this->expectException(InvalidSpecification::class);
Expand Down
Loading