api-platform / api-platform/core

Correct schema for associative arrays

オープン
#8,059 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る
metadata OpenAPI
主要言語
PHP
スター
2.6k
フォーク
980
平均マージ
2日 4時間
マージ済み PR(30日)
49

説明

**API Platform version(s) affected**: 3.0.3

**Description**
I tried various ways to annotate a field that has this kind of shape : array{ string => array }, but i keep getting "Object value found, but an array is required" in my tests when i use assertMatchesResourceItemJsonSchema .

The only annotation that "works" for tests is \stdClass, but that's hardly correct. I couldn't find anything relevant about this in the documentation, but i might have missed it?

**How to reproduce**
```php
#[ApiResource(
operations: [new Get(provider: BugProvider::class)] //provider.provide() only returns new Bug()
)]
class Bug
{
#[ApiProperty(identifier: true)]
public $id;

/**
* @var array $something
*/
public array $something = [];

public function __construct()
{
$this->id = 1;

$this->something = ['a' => ['val1', 'val2'], 'b' => ['whatever']];
}
}
```

Then a simple test :
```php
class BugTest extends ApiTestCase
{
function testBug(): void
{
self::createClient()->request('GET', '/bugs/1');
$this->assertResponseIsSuccessful();
$this->assertMatchesResourceItemJsonSchema(Bug::class);
}
}
```

and you get "something: Object value found, but an array is required".

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。