Skip to content

Commit 17233d9

Browse files
committed
Merge branch '4.0'
2 parents 9b5a358 + 4aeaacb commit 17233d9

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

ApiPlatformProvider.php

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,33 @@ public function register(): void
705705
/** @var ConfigRepository */
706706
$config = $app['config'];
707707

708-
return new Options(title: $config->get('api-platform.title') ?? '');
708+
return new Options(
709+
title: $config->get('api-platform.title', ''),
710+
description: $config->get('api-platform.description', ''),
711+
version: $config->get('api-platform.version', ''),
712+
oAuthEnabled: $config->get('api-platform.swagger_ui.oauth.enabled', false),
713+
oAuthType: $config->get('api-platform.swagger_ui.oauth.type', null),
714+
oAuthFlow: $config->get('api-platform.swagger_ui.oauth.flow', null),
715+
oAuthTokenUrl: $config->get('api-platform.swagger_ui.oauth.tokenUrl', null),
716+
oAuthAuthorizationUrl: $config->get('api-platform.swagger_ui.oauth.authorizationUrl', null),
717+
oAuthRefreshUrl: $config->get('api-platform.swagger_ui.oauth.refreshUrl', null),
718+
oAuthScopes: $config->get('api-platform.swagger_ui.oauth.scopes', []),
719+
apiKeys: $config->get('api-platform.swagger_ui.apiKeys', []),
720+
);
721+
});
722+
723+
$this->app->singleton(SwaggerUiProcessor::class, function (Application $app) {
724+
/** @var ConfigRepository */
725+
$config = $app['config'];
726+
727+
return new SwaggerUiProcessor(
728+
urlGenerator: $app->make(UrlGeneratorInterface::class),
729+
normalizer: $app->make(NormalizerInterface::class),
730+
openApiOptions: $app->make(Options::class),
731+
oauthClientId: $config->get('api-platform.swagger_ui.oauth.clientId'),
732+
oauthClientSecret: $config->get('api-platform.swagger_ui.oauth.clientSecret'),
733+
oauthPkce: $config->get('api-platform.swagger_ui.oauth.pkce', false),
734+
);
709735
});
710736

711737
$this->app->singleton(DocumentationController::class, function (Application $app) {
@@ -1267,14 +1293,6 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
12671293
$route->name('api_doc')->middleware(ApiPlatformMiddleware::class);
12681294
$routeCollection->add($route);
12691295

1270-
$route = new Route(['GET'], $prefix.'/{index?}{_format?}', function (Request $request, Application $app) {
1271-
$entrypointAction = $app->make(EntrypointController::class);
1272-
1273-
return $entrypointAction->__invoke($request);
1274-
});
1275-
$route->where('index', 'index');
1276-
$route->name('api_entrypoint')->middleware(ApiPlatformMiddleware::class);
1277-
$routeCollection->add($route);
12781296
$route = new Route(['GET'], $prefix.'/.well-known/genid/{id}', function (): void {
12791297
throw new NotExposedHttpException('This route is not exposed on purpose. It generates an IRI for a collection resource without identifier nor item operation.');
12801298
});
@@ -1297,6 +1315,15 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
12971315
$routeCollection->add($route);
12981316
}
12991317

1318+
$route = new Route(['GET'], $prefix.'/{index?}{_format?}', function (Request $request, Application $app) {
1319+
$entrypointAction = $app->make(EntrypointController::class);
1320+
1321+
return $entrypointAction->__invoke($request);
1322+
});
1323+
$route->where('index', 'index');
1324+
$route->name('api_entrypoint')->middleware(ApiPlatformMiddleware::class);
1325+
$routeCollection->add($route);
1326+
13001327
$router->setRoutes($routeCollection);
13011328
}
13021329

Eloquent/State/LinksHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ public function handleLinks(Builder $builder, array $uriVariables, array $contex
3737
$identifier = $uriVariables[$uriVariable];
3838

3939
if ($to = $link->getToProperty()) {
40-
$builder = $builder->where($builder->getModel()->getTable().'.'.$builder->getModel()->{$to}()->getForeignKeyName(), $identifier);
40+
$builder = $builder->where($builder->getModel()->{$to}()->getQualifiedForeignKeyName(), $identifier);
4141

4242
continue;
4343
}
4444

4545
if ($from = $link->getFromProperty()) {
4646
$relation = $this->application->make($link->getFromClass());
47-
$builder = $builder->getModel()->where($builder->getModel()->getTable().'.'.$relation->{$from}()->getForeignKeyName(), $identifier);
47+
$builder = $builder->getModel()->where($relation->{$from}()->getQualifiedForeignKeyName(), $identifier);
4848

4949
continue;
5050
}
5151

52-
$builder->where($builder->getModel()->getTable().'.'.$link->getIdentifiers()[0], $identifier);
52+
$builder->where($builder->getModel()->qualifyColumn($link->getIdentifiers()[0]), $identifier);
5353
}
5454

5555
return $builder;

State/SwaggerUiProcessor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function process(mixed $openApi, Operation $operation, array $uriVariable
7070
'flow' => $this->openApiOptions->getOAuthFlow(),
7171
'tokenUrl' => $this->openApiOptions->getOAuthTokenUrl(),
7272
'authorizationUrl' => $this->openApiOptions->getOAuthAuthorizationUrl(),
73+
'redirectUrl' => $request->getSchemeAndHttpHost().'/vendor/api-platform/swagger-ui/oauth2-redirect.html',
7374
'scopes' => $this->openApiOptions->getOAuthScopes(),
7475
'clientId' => $this->oauthClientId,
7576
'clientSecret' => $this->oauthClientSecret,

config/api-platform.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,24 @@
7272
],
7373

7474
'swagger_ui' => [
75-
'enabled' => true
75+
'enabled' => true,
76+
//'apiKeys' => [
77+
// 'api' => [
78+
// 'type' => 'Bearer',
79+
// 'name' => 'Authentication Token',
80+
// 'in' => 'header'
81+
// ]
82+
//],
83+
//'oauth' => [
84+
// 'enabled' => true,
85+
// 'type' => 'oauth2',
86+
// 'flow' => 'authorizationCode',
87+
// 'tokenUrl' => '',
88+
// 'authorizationUrl' =>'',
89+
// 'refreshUrl' => '',
90+
// 'scopes' => ['scope1' => 'Description scope 1'],
91+
// 'pkce' => true
92+
//]
7693
],
7794

7895
'url_generation_strategy' => UrlGeneratorInterface::ABS_PATH,

0 commit comments

Comments
 (0)