Skip to content

Commit ebc61d5

Browse files
authored
fix(laravel): entrypoint serialization (#6541)
1 parent 4ee209e commit ebc61d5

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/Documentation/Action/EntrypointAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public function __construct(
3737
private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory,
3838
private readonly ProviderInterface $provider,
3939
private readonly ProcessorInterface $processor,
40-
private readonly array $documentationFormats = []
40+
private readonly array $documentationFormats = [],
4141
) {
4242
}
4343

4444
public function __invoke(Request $request)
4545
{
46-
static::$resourceNameCollection = $this->resourceNameCollectionFactory->create();
46+
self::$resourceNameCollection = $this->resourceNameCollectionFactory->create();
4747
$context = [
4848
'request' => $request,
4949
'spec_version' => (string) $request->query->get(LegacyOpenApiNormalizer::SPEC_VERSION),
@@ -65,6 +65,6 @@ class: Entrypoint::class,
6565

6666
public static function provide(): Entrypoint
6767
{
68-
return new Entrypoint(static::$resourceNameCollection);
68+
return new Entrypoint(self::$resourceNameCollection);
6969
}
7070
}

src/Laravel/ApiPlatformProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ public function register(): void
535535
return new DocumentationAction($app->make(ResourceNameCollectionFactoryInterface::class), $config->get('api-platform.title') ?? '', $config->get('api-platform.description') ?? '', $config->get('api-platform.version') ?? '', $app->make(OpenApiFactoryInterface::class), $app->make(ProviderInterface::class), $app->make(ProcessorInterface::class), $app->make(Negotiator::class), $config->get('api-platform.docs_formats'));
536536
});
537537

538-
$this->app->singleton(EntrypointAction::class, function (Application $app) {
539-
return new EntrypointAction($app->make(ResourceNameCollectionFactoryInterface::class), $app->make(ProviderInterface::class), $app->make(ProcessorInterface::class), ['jsonld' => ['application/ld+json']]);
538+
$this->app->singleton(EntrypointAction::class, function (Application $app) use ($config) {
539+
return new EntrypointAction($app->make(ResourceNameCollectionFactoryInterface::class), $app->make(ProviderInterface::class), $app->make(ProcessorInterface::class), $config->get('api-platform.formats'));
540540
});
541541

542542
$this->app->singleton(Pagination::class, function () use ($config) {

src/Laravel/Eloquent/Metadata/ModelMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function getRelations(Model $model): Collection
179179
$file->next();
180180
}
181181

182-
return collect(static::RELATION_METHODS)
182+
return collect(self::RELATION_METHODS)
183183
->contains(fn ($relationMethod) => str_contains($code, '$this->'.$relationMethod.'('));
184184
})
185185
->map(function (\ReflectionMethod $method) use ($model) {

src/Laravel/Tests/JsonApiTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ protected function defineEnvironment($app): void
3838
});
3939
}
4040

41+
public function testGetEntrypoint(): void
42+
{
43+
$response = $this->get('/api/', ['accept' => ['application/vnd.api+json']]);
44+
$response->assertStatus(200);
45+
$response->assertHeader('content-type', 'application/vnd.api+json; charset=utf-8');
46+
$this->assertJsonContains([
47+
'links' => [
48+
'self' => 'http://localhost/api',
49+
'book' => 'http://localhost/api/books',
50+
],
51+
],
52+
$response->json());
53+
}
54+
4155
public function testGetCollection(): void
4256
{
4357
$response = $this->get('/api/books', ['accept' => ['application/vnd.api+json']]);

0 commit comments

Comments
 (0)