From f1bfb0e8ec45cc979320d1c51284b0e8f6476ce7 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 20 Aug 2026 21:31:51 +0530 Subject: [PATCH] fix: allow derived enum keys --- src/Parser/Schema/Reader.php | 2 +- tests/Schema/ReaderTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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);