diff --git a/src/Parser/Schema/Reader.php b/src/Parser/Schema/Reader.php index e278e01..09f4789 100644 --- a/src/Parser/Schema/Reader.php +++ b/src/Parser/Schema/Reader.php @@ -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}"); } diff --git a/tests/Schema/ReaderTest.php b/tests/Schema/ReaderTest.php index 9539580..f812757 100644 --- a/tests/Schema/ReaderTest.php +++ b/tests/Schema/ReaderTest.php @@ -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);