Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass enums through array_values #549

Merged
merged 2 commits into from
May 15, 2024
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
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']);
}
}
Loading