Skip to content

Commit d22c657

Browse files
committed
Fixed some required flags and ID to be required and readonly
1 parent 2bb4a2c commit d22c657

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/OpenApi/OpenApiGenerator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function generate(JsonApi $api): array
6262
$type = $resource->type();
6363

6464
$schemas[$type] = $this->buildSchema($resource, $schema, [
65+
'required' => ['id'],
6566
'properties' => ['id' => ['type' => 'string', 'readOnly' => true]],
6667
]);
6768

@@ -89,10 +90,17 @@ public function generate(JsonApi $api): array
8990

9091
private function buildSchema(Resource $resource, array $schema, array $overrides = []): array
9192
{
93+
$hasAttributes = !empty($schema['attributes']);
94+
$hasRelationships = !empty($schema['relationships']);
95+
9296
return array_replace_recursive(
9397
[
9498
'type' => 'object',
95-
'required' => ['type'],
99+
'required' => array_filter([
100+
'type',
101+
$hasAttributes ? 'attributes' : null,
102+
$hasRelationships ? 'relationships' : null,
103+
]),
96104
'properties' => [
97105
'type' => ['type' => 'string', 'const' => $resource->type()],
98106
'attributes' => ['type' => 'object'] + ($schema['attributes'] ?? []),

0 commit comments

Comments
 (0)