Skip to content

Commit 7f13b89

Browse files
committed
Fixed an issue where id was required even in create requests
1 parent 20271bc commit 7f13b89

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/OpenApi/OpenApiGenerator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ public function generate(JsonApi $api): array
6565
'properties' => ['id' => ['type' => 'string', 'readOnly' => true]],
6666
]);
6767

68-
$schemas["{$type}Create"] = $this->buildSchema($resource, $createSchema, [
69-
'required' => ['type'],
70-
]);
68+
$schemas["{$type}Create"] = $this->buildSchema($resource, $createSchema);
7169

72-
$schemas["{$type}Update"] = $this->buildSchema($resource, $updateSchema);
70+
$schemas["{$type}Update"] = $this->buildSchema($resource, $updateSchema, [
71+
'required' => ['type', 'id'],
72+
'properties' => ['id' => ['type' => 'string']],
73+
]);
7374
}
7475

7576
return array_filter([
@@ -91,10 +92,9 @@ private function buildSchema(Resource $resource, array $schema, array $overrides
9192
return array_replace_recursive(
9293
[
9394
'type' => 'object',
94-
'required' => ['type', 'id'],
95+
'required' => ['type'],
9596
'properties' => [
9697
'type' => ['type' => 'string', 'const' => $resource->type()],
97-
'id' => ['type' => 'string'],
9898
'attributes' => ['type' => 'object'] + ($schema['attributes'] ?? []),
9999
'relationships' => ['type' => 'object'] + ($schema['relationships'] ?? []),
100100
],

0 commit comments

Comments
 (0)