Skip to content

Commit e493f7e

Browse files
committed
Make sure empty schemas are encoded as objects instead of arrays
1 parent c512c52 commit e493f7e

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

src/Endpoint/Concerns/SerializesDocument.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ private function documentSchema(SchemaContext $context, array $schemaProviders =
3131
foreach ($schemaProviders as $provider) {
3232
if ($provider instanceof ProvidesDocumentMeta) {
3333
foreach ($provider->documentMeta() as $m) {
34-
$meta[$m->name] = $m->getSchema($context);
34+
$meta[$m->name] = (object) $m->getSchema($context);
3535
}
3636
}
3737

3838
if ($provider instanceof ProvidesDocumentLinks) {
3939
foreach ($provider->documentLinks() as $link) {
40-
$links[$link->name] = $link->getSchema($context);
40+
$links[$link->name] = (object) $link->getSchema($context);
4141
}
4242
}
4343
}
4444

4545
foreach ($this->meta as $m) {
46-
$meta[$m->name] = $m->getSchema($context);
46+
$meta[$m->name] = (object) $m->getSchema($context);
4747
}
4848

4949
return [

src/Resource/AbstractResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function rootSchema(SchemaContext $context): array
7171

7272
$updateSchema = array_merge_recursive($schema, [
7373
'required' => ['id'],
74-
'properties' => ['id' => $id->getSchema($context)],
74+
'properties' => ['id' => (object) $id->getSchema($context)],
7575
]);
7676

7777
foreach ([$id, ...$this->fields()] as $field) {

src/Schema/Concerns/HasSchema.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Tobyz\JsonApiServer\Schema\Concerns;
44

5+
use Tobyz\JsonApiServer\SchemaContext;
6+
57
trait HasSchema
68
{
79
protected array $schema = [];
@@ -29,7 +31,7 @@ public function description(?string $description): static
2931
/**
3032
* Get the custom schema.
3133
*/
32-
private function getSchema(): array
34+
private function getSchema(SchemaContext $context): array
3335
{
3436
return $this->schema;
3537
}

src/Schema/Parameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getSchema(SchemaContext $context): array
6363
$schema = [
6464
'name' => $this->name,
6565
'in' => $this->in,
66-
'schema' => $this->type?->schema() ?: [],
66+
'schema' => $this->type?->schema() ?: (object) [],
6767
...parent::getSchema($context),
6868
];
6969

src/Schema/Sort.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace Tobyz\JsonApiServer\Schema;
44

55
use Tobyz\JsonApiServer\Context;
6-
use Tobyz\JsonApiServer\Schema\Concerns\HasSchema;
76
use Tobyz\JsonApiServer\Schema\Concerns\HasVisibility;
87

98
abstract class Sort
109
{
11-
use HasSchema;
1210
use HasVisibility;
1311

1412
public function __construct(public string $name)

0 commit comments

Comments
 (0)