From c3a4c2e519ca81c04eb64f471fd04918baa1378e Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Wed, 15 May 2024 07:57:32 -0400 Subject: [PATCH 1/2] Pass enums through array_values --- src/Lib/OpenApi/SchemaProperty.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Lib/OpenApi/SchemaProperty.php b/src/Lib/OpenApi/SchemaProperty.php index c1556a8e..5f5b3fa9 100644 --- a/src/Lib/OpenApi/SchemaProperty.php +++ b/src/Lib/OpenApi/SchemaProperty.php @@ -118,6 +118,10 @@ public function toArray(): array ['readOnly' => false, 'writeOnly' => false, 'deprecated' => false, 'nullable' => false] ); + if (isset($vars['enum']) && is_array($vars['enum'])) { + $vars['enum'] = array_values($vars['enum']); + } + return $vars; } From 956af81aedc5ff030acc18f6534a9e567ea1e418 Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Wed, 15 May 2024 08:01:18 -0400 Subject: [PATCH 2/2] adds coverage --- tests/TestCase/Lib/OpenApi/SchemaPropertyTest.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/TestCase/Lib/OpenApi/SchemaPropertyTest.php b/tests/TestCase/Lib/OpenApi/SchemaPropertyTest.php index 9c6034bc..22bad89c 100644 --- a/tests/TestCase/Lib/OpenApi/SchemaPropertyTest.php +++ b/tests/TestCase/Lib/OpenApi/SchemaPropertyTest.php @@ -1,9 +1,10 @@ expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new SchemaProperty('test', 'invalid'); } -} \ No newline at end of file + + public function test_enum_properties_is_indexed_numerically(): void + { + $vars = (new SchemaProperty())->setEnum(['test' => 'test'])->toArray(); + $this->assertArrayHasKey(0, $vars['enum']); + } +}