Skip to content

Commit d3a6039

Browse files
committed
Merge branch '4.0'
2 parents cead16a + a259d46 commit d3a6039

File tree

17 files changed

+95
-68
lines changed

17 files changed

+95
-68
lines changed

features/hydra/error.feature

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ Feature: Error handling
1717
And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
1818
And the JSON node "type" should exist
1919
And the JSON node "title" should be equal to "An error occurred"
20-
And the JSON node "hydra:title" should be equal to "An error occurred"
2120
And the JSON node "detail" should exist
22-
And the JSON node "hydra:description" should exist
21+
And the JSON node "description" should exist
2322
And the JSON node "trace" should exist
2423
And the JSON node "status" should exist
2524
And the JSON node "@context" should exist
@@ -48,10 +47,9 @@ Feature: Error handling
4847
}
4948
],
5049
"detail": "name: This value should not be blank.",
51-
"hydra:title": "An error occurred",
52-
"hydra:description": "name: This value should not be blank.",
53-
"type": "/validation_errors/c1051bb4-d103-4f74-8988-acbcafc7fdc3",
54-
"title": "An error occurred"
50+
"title": "An error occurred",
51+
"description": "name: This value should not be blank.",
52+
"type": "/validation_errors/c1051bb4-d103-4f74-8988-acbcafc7fdc3"
5553
}
5654
"""
5755

@@ -83,9 +81,8 @@ Feature: Error handling
8381
And the JSON node "@context" should exist
8482
And the JSON node "type" should exist
8583
And the JSON node "title" should be equal to "An error occurred"
86-
And the JSON node "hydra:title" should be equal to "An error occurred"
8784
And the JSON node "detail" should exist
88-
And the JSON node "hydra:description" should exist
85+
And the JSON node "description" should exist
8986

9087
Scenario: Get an rfc 7807 bad method error
9188
When I add "Content-Type" header equal to "application/ld+json"
@@ -101,9 +98,8 @@ Feature: Error handling
10198
And the JSON node "@context" should exist
10299
And the JSON node "type" should exist
103100
And the JSON node "title" should be equal to "An error occurred"
104-
And the JSON node "hydra:title" should be equal to "An error occurred"
105101
And the JSON node "detail" should exist
106-
And the JSON node "hydra:description" should exist
102+
And the JSON node "description" should exist
107103

108104
Scenario: Get an rfc 7807 validation error
109105
When I add "Content-Type" header equal to "application/ld+json"

features/jsonld/input_output.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Feature: JSON-LD DTO input and output
309309
"""
310310
Then the response status code should be 400
311311
And the response should be in JSON
312-
And the JSON node "hydra:description" should be equal to "The input data is misformatted."
312+
And the JSON node "description" should be equal to "The input data is misformatted."
313313

314314
@!mongodb
315315
Scenario: Reset password through an input DTO without DataTransformer

features/main/attribute_resource.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Feature: Resource attributes
100100
And the response should be in JSON
101101
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
102102
And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
103-
And the JSON node "hydra:description" should be equal to 'Unable to generate an IRI for the item of type "ApiPlatform\Tests\Fixtures\TestBundle\Entity\IncompleteUriVariableConfigured"'
103+
And the JSON node "description" should be equal to 'Unable to generate an IRI for the item of type "ApiPlatform\Tests\Fixtures\TestBundle\Entity\IncompleteUriVariableConfigured"'
104104

105105
Scenario: Uri variables with Post operation
106106
When I add "Content-Type" header equal to "application/ld+json"

features/main/not_exposed.feature

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,22 @@ Feature: Expose only a collection of objects
171171
When I send a "GET" request to "<uri>"
172172
Then the response status code should be 404
173173
And the response should be in JSON
174-
And the JSON node "hydra:description" should be equal to "<hydra:description>"
174+
And the JSON node "hydra:description" should be equal to "<description>"
175175
Examples:
176-
| uri | hydra:description |
177-
| /.well-known/genid/12345 | This route is not exposed on purpose. It generates an IRI for a collection resource without identifier nor item operation. |
176+
| uri | description |
178177
| /tables/12345 | This route does not aim to be called. |
179178
| /forks/12345 | This route does not aim to be called. |
180179

180+
Scenario Outline: Get a not exposed route returns a 404 with an explanation
181+
When I send a "GET" request to "<uri>"
182+
Then the response status code should be 404
183+
And the response should be in JSON
184+
And the JSON node "description" should be equal to "<description>"
185+
Examples:
186+
| uri | description |
187+
| /.well-known/genid/12345 | This route is not exposed on purpose. It generates an IRI for a collection resource without identifier nor item operation. |
188+
189+
181190
Scenario: Get a single item still works
182191
When I send a "GET" request to "/cuillers/12345"
183192
Then the response status code should be 200

features/main/relation.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ Feature: Relations support
472472
Then the response status code should be 400
473473
And the response should be in JSON
474474
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
475-
And the JSON node "hydra:description" should contain 'Invalid IRI "certainly not an IRI".'
475+
And the JSON node "description" should contain 'Invalid IRI "certainly not an IRI".'
476476

477477
Scenario: Passing an invalid type to a relation
478478
When I add "Content-Type" header equal to "application/ld+json"
@@ -493,20 +493,20 @@ Feature: Relations support
493493
"properties": {
494494
"@type": {
495495
"type": "string",
496-
"pattern": "^hydra:Error$"
496+
"pattern": "^Error$"
497497
},
498-
"hydra:title": {
498+
"title": {
499499
"type": "string",
500500
"pattern": "^An error occurred$"
501501
},
502-
"hydra:description": {
502+
"description": {
503503
"pattern": "^The type of the \"ApiPlatform\\\\Tests\\\\Fixtures\\\\TestBundle\\\\(Document|Entity)\\\\RelatedDummy\" resource must be \"array\" \\(nested document\\) or \"string\" \\(IRI\\), \"integer\" given.$"
504504
}
505505
},
506506
"required": [
507507
"@type",
508-
"hydra:title",
509-
"hydra:description"
508+
"title",
509+
"description"
510510
]
511511
}
512512
"""

features/main/union_intersect_types.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@ Feature: Union/Intersect types
118118
Then the response status code should be 400
119119
And the response should be in JSON
120120
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
121-
And the JSON node "hydra:description" should be equal to 'Could not denormalize object of type "ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5452\ActivableInterface", no supporting normalizer found.'
121+
And the JSON node "description" should be equal to 'Could not denormalize object of type "ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5452\ActivableInterface", no supporting normalizer found.'

features/main/validation.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Feature: Using validations groups
8787
And the JSON node "violations[0].message" should be equal to "This value should not be null."
8888
And the JSON node "violations[0].propertyPath" should be equal to "test"
8989
And the JSON node "detail" should be equal to "test: This value should not be null."
90-
And the JSON node "hydra:description" should be equal to "test: This value should not be null."
90+
And the JSON node "description" should be equal to "test: This value should not be null."
9191
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
9292

9393
@!mongodb

features/serializer/vo_relations.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,20 @@ Feature: Value object as ApiResource
148148
"properties": {
149149
"@type": {
150150
"type": "string",
151-
"pattern": "^hydra:Error$"
151+
"pattern": "^Error$"
152152
},
153-
"hydra:title": {
153+
"title": {
154154
"type": "string",
155155
"pattern": "^An error occurred$"
156156
},
157-
"hydra:description": {
157+
"description": {
158158
"pattern": "^Cannot create an instance of \"ApiPlatform\\\\Tests\\\\Fixtures\\\\TestBundle\\\\(Document|Entity)\\\\VoDummyCar\" from serialized data because its constructor requires the following parameters to be present : \"\\$drivers\".$"
159159
}
160160
},
161161
"required": [
162162
"@type",
163-
"hydra:title",
164-
"hydra:description"
163+
"title",
164+
"description"
165165
]
166166
}
167167
"""

src/JsonLd/ContextBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\JsonLd;
1515

1616
use ApiPlatform\JsonLd\Serializer\HydraPrefixTrait;
17+
use ApiPlatform\Metadata\Error;
1718
use ApiPlatform\Metadata\Get;
1819
use ApiPlatform\Metadata\HttpOperation;
1920
use ApiPlatform\Metadata\IriConverterInterface;
@@ -184,7 +185,7 @@ private function getResourceContextWithShortname(string $resourceClass, int $ref
184185
}
185186
}
186187

187-
if (false === ($this->defaultContext[self::HYDRA_CONTEXT_HAS_PREFIX] ?? true)) {
188+
if (false === ($this->defaultContext[self::HYDRA_CONTEXT_HAS_PREFIX] ?? true) || $operation instanceof Error) {
188189
return ['http://www.w3.org/ns/hydra/context.jsonld', $context];
189190
}
190191

src/Laravel/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

0 commit comments

Comments
 (0)