Skip to content

Commit 5b215f0

Browse files
committed
Added the ability to pass the collection name to create collection docs properly
1 parent 59f541a commit 5b215f0

File tree

6 files changed

+11
-3
lines changed

6 files changed

+11
-3
lines changed

src/Endpoint/Concerns/BuildsOpenApiPaths.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
trait BuildsOpenApiPaths
1515
{
1616
private function buildOpenApiContent(
17+
string $name,
1718
array $resources,
1819
bool $multiple = false,
1920
bool $included = true,
@@ -27,7 +28,7 @@ private function buildOpenApiContent(
2728
'type' => 'object',
2829
'required' => ['data'],
2930
'properties' => array_filter([
30-
'links' => $links ? $this->buildLinksObject($item) : [],
31+
'links' => $links ? $this->buildLinksObject($name) : [],
3132
'data' => $multiple ? ['type' => 'array', 'items' => $item] : $item,
3233
'included' => $included ? ['type' => 'array'] : [],
3334
]),
@@ -36,10 +37,10 @@ private function buildOpenApiContent(
3637
];
3738
}
3839

39-
private function buildLinksObject(array $item): array
40+
private function buildLinksObject(string $name): array
4041
{
4142
// @todo: maybe pull in the API or Context to return a server name?
42-
$baseUri = sprintf('https://{server}/%s', $this->findResourceFromItem($item));
43+
$baseUri = sprintf('https://{server}/%s', $name);
4344
$defaultQuery = ['page[limit]' => 10];
4445

4546
$links = [

src/Endpoint/Create.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function getOpenApiPaths(Collection $collection): array
118118
'requestBody' => [
119119
'required' => true,
120120
'content' => $this->buildOpenApiContent(
121+
$collection->name(),
121122
array_map(
122123
fn($resource) => [
123124
'$ref' => "#/components/schemas/{$resource}Create",
@@ -130,6 +131,7 @@ public function getOpenApiPaths(Collection $collection): array
130131
'200' => [
131132
'description' => 'Resource created successfully.',
132133
'content' => $this->buildOpenApiContent(
134+
$collection->name(),
133135
array_map(
134136
fn($resource) => ['$ref' => "#/components/schemas/$resource"],
135137
$collection->resources(),

src/Endpoint/Index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public function getOpenApiPaths(Collection $collection): array
192192
'200' => [
193193
'description' => 'Successful list all response.',
194194
'content' => $this->buildOpenApiContent(
195+
$collection->name(),
195196
array_map(
196197
fn($resource) => ['$ref' => "#/components/schemas/$resource"],
197198
$collection->resources(),

src/Endpoint/ResourceAction.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function getOpenApiPaths(Collection $collection): array
9292
'200' => [
9393
'description' => 'Successful custom action response.',
9494
'content' => $this->buildOpenApiContent(
95+
$collection->name(),
9596
array_map(
9697
fn($resource) => ['$ref' => "#/components/schemas/$resource"],
9798
$collection->resources(),

src/Endpoint/Show.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function getOpenApiPaths(Collection $collection): array
7777
'200' => [
7878
'description' => 'Successful show response.',
7979
'content' => $this->buildOpenApiContent(
80+
$collection->name(),
8081
array_map(
8182
fn($resource) => ['$ref' => "#/components/schemas/$resource"],
8283
$collection->resources(),

src/Endpoint/Update.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function getOpenApiPaths(Collection $collection): array
9898
'requestBody' => [
9999
'required' => true,
100100
'content' => $this->buildOpenApiContent(
101+
$collection->name(),
101102
array_map(
102103
fn($resource) => [
103104
'$ref' => "#/components/schemas/{$resource}Update",
@@ -110,6 +111,7 @@ public function getOpenApiPaths(Collection $collection): array
110111
'200' => [
111112
'description' => 'Successful update response.',
112113
'content' => $this->buildOpenApiContent(
114+
$collection->name(),
113115
array_map(
114116
fn($resource) => ['$ref' => "#/components/schemas/$resource"],
115117
$collection->resources(),

0 commit comments

Comments
 (0)