Skip to content

Commit

Permalink
Pass enums through array_values (#549)
Browse files Browse the repository at this point in the history
* Pass enums through array_values
  • Loading branch information
cnizzardini committed May 15, 2024
1 parent cbb7f7c commit 9a24990
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Lib/OpenApi/SchemaProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 10 additions & 3 deletions tests/TestCase/Lib/OpenApi/SchemaPropertyTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
declare(strict_types=1);

namespace SwaggerBake\Test\TestCase\Lib\OpenApi;

use Cake\TestSuite\TestCase;
use SwaggerBake\Lib\OpenApi\Schema;
use InvalidArgumentException;
use SwaggerBake\Lib\OpenApi\SchemaProperty;

class SchemaPropertyTest extends TestCase
Expand All @@ -21,7 +22,13 @@ public function test_example_is_json_encoded_when_blank(): void

public function test_invalid_type_throws_exception(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
new SchemaProperty('test', 'invalid');
}
}

public function test_enum_properties_is_indexed_numerically(): void
{
$vars = (new SchemaProperty())->setEnum(['test' => 'test'])->toArray();
$this->assertArrayHasKey(0, $vars['enum']);
}
}

0 comments on commit 9a24990

Please sign in to comment.