Skip to content

Commit 9bcbc1c

Browse files
committed
Merge 4.0
2 parents 6f334fe + 5a5ec1a commit 9bcbc1c

File tree

20 files changed

+265
-32
lines changed

20 files changed

+265
-32
lines changed

features/hydra/collection.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ Feature: Collections support
480480

481481
When I send a "GET" request to "/dummies?itemsPerPage=0&page=2"
482482
Then the response status code should be 400
483-
And the JSON node "hydra:description" should be equal to "Page should not be greater than 1 if limit is equal to 0"
483+
And the JSON node "description" should be equal to "Page should not be greater than 1 if limit is equal to 0"
484484

485485
Scenario: Cursor-based pagination with an empty collection
486486
When I send a "GET" request to "/so_manies"

features/main/crud.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Feature: Create-Retrieve-Update-Delete
9595
When I add "Content-Type" header equal to "application/ld+json"
9696
And I send a "POST" request to "/dummies"
9797
Then the response status code should be 400
98-
And the JSON node "hydra:description" should be equal to "Syntax error"
98+
And the JSON node "description" should be equal to "Syntax error"
9999

100100
Scenario: Get a not found exception
101101
When I send a "GET" request to "/dummies/42"
@@ -552,7 +552,7 @@ Feature: Create-Retrieve-Update-Delete
552552
When I add "Content-Type" header equal to "application/ld+json"
553553
And I send a "PUT" request to "/dummies/1"
554554
Then the response status code should be 400
555-
And the JSON node "hydra:description" should be equal to "Syntax error"
555+
And the JSON node "description" should be equal to "Syntax error"
556556

557557
Scenario: Delete a resource
558558
When I send a "DELETE" request to "/dummies/1"

features/main/not_exposed.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ 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 "<description>"
174+
And the JSON node "description" should be equal to "<description>"
175175
Examples:
176176
| uri | description |
177177
| /tables/12345 | This route does not aim to be called. |

features/main/validation.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Feature: Using validations groups
3131
{
3232
"@context": "/contexts/ConstraintViolationList",
3333
"@type": "ConstraintViolationList",
34-
"hydra:title": "An error occurred",
35-
"hydra:description": "name: This value should not be null.",
34+
"title": "An error occurred",
35+
"description": "name: This value should not be null.",
3636
"violations": [
3737
{
3838
"propertyPath": "name",
@@ -60,8 +60,8 @@ Feature: Using validations groups
6060
{
6161
"@context": "/contexts/ConstraintViolationList",
6262
"@type": "ConstraintViolationList",
63-
"hydra:title": "An error occurred",
64-
"hydra:description": "title: This value should not be null.",
63+
"title": "An error occurred",
64+
"description": "title: This value should not be null.",
6565
"violations": [
6666
{
6767
"propertyPath": "title",
@@ -113,8 +113,8 @@ Feature: Using validations groups
113113
{
114114
"@context": "/contexts/ConstraintViolationList",
115115
"@type": "ConstraintViolationList",
116-
"hydra:title": "An error occurred",
117-
"hydra:description": "This value should be of type unknown.\nqux: This value should be of type string.\nfoo: This value should be of type bool.\nbar: This value should be of type int.\nuuid: This value should be of type uuid.\nrelatedDummy: This value should be of type array|string.\nrelatedDummies: This value should be of type array.",
116+
"title": "An error occurred",
117+
"description": "This value should be of type unknown.\nqux: This value should be of type string.\nfoo: This value should be of type bool.\nbar: This value should be of type int.\nuuid: This value should be of type uuid.\nrelatedDummy: This value should be of type array|string.\nrelatedDummies: This value should be of type array.",
118118
"violations": [
119119
{
120120
"propertyPath": "",

features/security/strong_typing.feature

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ Feature: Handle properly invalid data submitted to the API
5454
And the response should be in JSON
5555
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
5656
And the JSON node "@context" should be equal to "/contexts/Error"
57-
And the JSON node "@type" should be equal to "hydra:Error"
58-
And the JSON node "hydra:title" should be equal to "An error occurred"
59-
And the JSON node "hydra:description" should be equal to 'The type of the "name" attribute must be "string", "NULL" given.'
57+
And the JSON node "@type" should be equal to "Error"
58+
And the JSON node "title" should be equal to "An error occurred"
59+
And the JSON node "description" should be equal to 'The type of the "name" attribute must be "string", "NULL" given.'
6060

6161
Scenario: Create a resource with wrong value type for relation
6262
When I add "Content-Type" header equal to "application/ld+json"
@@ -71,9 +71,9 @@ Feature: Handle properly invalid data submitted to the API
7171
And the response should be in JSON
7272
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
7373
And the JSON node "@context" should be equal to "/contexts/Error"
74-
And the JSON node "@type" should be equal to "hydra:Error"
75-
And the JSON node "hydra:title" should be equal to "An error occurred"
76-
And the JSON node "hydra:description" should be equal to 'Invalid IRI "1".'
74+
And the JSON node "@type" should be equal to "Error"
75+
And the JSON node "title" should be equal to "An error occurred"
76+
And the JSON node "description" should be equal to 'Invalid IRI "1".'
7777
And the JSON node "trace" should exist
7878

7979
Scenario: Ignore invalid dates
@@ -102,9 +102,9 @@ Feature: Handle properly invalid data submitted to the API
102102
And the response should be in JSON
103103
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
104104
And the JSON node "@context" should be equal to "/contexts/Error"
105-
And the JSON node "@type" should be equal to "hydra:Error"
106-
And the JSON node "hydra:title" should be equal to "An error occurred"
107-
And the JSON node "hydra:description" should be equal to 'The type of the "relatedDummies" attribute must be "array", "string" given.'
105+
And the JSON node "@type" should be equal to "Error"
106+
And the JSON node "title" should be equal to "An error occurred"
107+
And the JSON node "description" should be equal to 'The type of the "relatedDummies" attribute must be "array", "string" given.'
108108
And the JSON node "trace" should exist
109109

110110
Scenario: Send an object where an array is expected
@@ -120,9 +120,9 @@ Feature: Handle properly invalid data submitted to the API
120120
And the response should be in JSON
121121
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
122122
And the JSON node "@context" should be equal to "/contexts/Error"
123-
And the JSON node "@type" should be equal to "hydra:Error"
124-
And the JSON node "hydra:title" should be equal to "An error occurred"
125-
And the JSON node "hydra:description" should be equal to 'The type of the key "a" must be "int", "string" given.'
123+
And the JSON node "@type" should be equal to "Error"
124+
And the JSON node "title" should be equal to "An error occurred"
125+
And the JSON node "description" should be equal to 'The type of the key "a" must be "int", "string" given.'
126126

127127
Scenario: Send a scalar having the bad type
128128
When I add "Content-Type" header equal to "application/ld+json"
@@ -136,9 +136,9 @@ Feature: Handle properly invalid data submitted to the API
136136
And the response should be in JSON
137137
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
138138
And the JSON node "@context" should be equal to "/contexts/Error"
139-
And the JSON node "@type" should be equal to "hydra:Error"
140-
And the JSON node "hydra:title" should be equal to "An error occurred"
141-
And the JSON node "hydra:description" should be equal to 'The type of the "name" attribute must be "string", "integer" given.'
139+
And the JSON node "@type" should be equal to "Error"
140+
And the JSON node "title" should be equal to "An error occurred"
141+
And the JSON node "description" should be equal to 'The type of the "name" attribute must be "string", "integer" given.'
142142

143143
Scenario: According to the JSON spec, allow numbers without explicit floating point for JSON formats
144144
When I add "Content-Type" header equal to "application/ld+json"

features/security/validate_incoming_content-types.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ Feature: Validate incoming content type
1414
"""
1515
Then the response status code should be 415
1616
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
17-
And the JSON node "hydra:description" should be equal to 'The content-type "text/plain" is not supported. Supported MIME types are "application/ld+json", "application/hal+json", "application/vnd.api+json", "application/xml", "text/xml", "application/json", "text/html", "application/graphql", "multipart/form-data".'
17+
And the JSON node "description" should be equal to 'The content-type "text/plain" is not supported. Supported MIME types are "application/ld+json", "application/hal+json", "application/vnd.api+json", "application/xml", "text/xml", "application/json", "text/html", "application/graphql", "multipart/form-data".'

src/JsonSchema/DefinitionNameFactory.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ final class DefinitionNameFactory implements DefinitionNameFactoryInterface
2121
{
2222
use ResourceClassInfoTrait;
2323

24+
private const GLUE = '.';
25+
private array $prefixCache = [];
26+
2427
public function __construct(private ?array $distinctFormats)
2528
{
2629
}
@@ -32,18 +35,18 @@ public function create(string $className, string $format = 'json', ?string $inpu
3235
}
3336

3437
if (!isset($prefix)) {
35-
$prefix = (new \ReflectionClass($className))->getShortName();
38+
$prefix = $this->createPrefixFromClass($className);
3639
}
3740

3841
if (null !== $inputOrOutputClass && $className !== $inputOrOutputClass) {
3942
$parts = explode('\\', $inputOrOutputClass);
4043
$shortName = end($parts);
41-
$prefix .= '.'.$shortName;
44+
$prefix .= self::GLUE.$shortName;
4245
}
4346

4447
if ('json' !== $format && ($this->distinctFormats[$format] ?? false)) {
4548
// JSON is the default, and so isn't included in the definition name
46-
$prefix .= '.'.$format;
49+
$prefix .= self::GLUE.$format;
4750
}
4851

4952
$definitionName = $serializerContext[SchemaFactory::OPENAPI_DEFINITION_NAME] ?? null;
@@ -61,4 +64,22 @@ private function encodeDefinitionName(string $name): string
6164
{
6265
return preg_replace('/[^a-zA-Z0-9.\-_]/', '.', $name);
6366
}
67+
68+
private function createPrefixFromClass(string $fullyQualifiedClassName, int $namespaceParts = 1): string
69+
{
70+
$parts = explode('\\', $fullyQualifiedClassName);
71+
$name = implode(self::GLUE, \array_slice($parts, -$namespaceParts));
72+
73+
if (!isset($this->prefixCache[$name])) {
74+
$this->prefixCache[$name] = $fullyQualifiedClassName;
75+
76+
return $name;
77+
}
78+
79+
if ($this->prefixCache[$name] !== $fullyQualifiedClassName) {
80+
$name = $this->createPrefixFromClass($fullyQualifiedClassName, ++$namespaceParts);
81+
}
82+
83+
return $name;
84+
}
6485
}

src/Laravel/Eloquent/Metadata/Factory/Property/EloquentPropertyMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function create(string $resourceClass, string $property, array $options =
7777
'collection', 'encrypted:collection' => new Type(Type::BUILTIN_TYPE_ITERABLE, $p['nullable'], Collection::class, true),
7878
'encrypted:array' => new Type(Type::BUILTIN_TYPE_ARRAY, $p['nullable']),
7979
'encrypted:object' => new Type(Type::BUILTIN_TYPE_OBJECT, $p['nullable']),
80-
default => new Type(\in_array($builtinType, Type::$builtinTypes, true) ? $builtinType : Type::BUILTIN_TYPE_STRING, $p['nullable']),
80+
default => new Type(\in_array($builtinType, Type::$builtinTypes, true) ? $builtinType : Type::BUILTIN_TYPE_STRING, $p['nullable'] ?? true),
8181
};
8282

8383
return $propertyMetadata

src/Laravel/Eloquent/Metadata/Factory/Property/EloquentPropertyNameCollectionMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function create(string $resourceClass, array $options = []): PropertyName
5353

5454
// When it's an Eloquent model we read attributes from database (@see ShowModelCommand)
5555
foreach ($this->modelMetadata->getAttributes($model) as $property) {
56-
if (!$property['primary'] && $property['hidden']) {
56+
if (!($property['primary'] ?? null) && $property['hidden']) {
5757
continue;
5858
}
5959

src/Laravel/Tests/EloquentTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,10 @@ public function testWrongOrderFilter(): void
368368
$res = $this->get('/api/authors?order[name]=something', ['Accept' => ['application/ld+json']]);
369369
$this->assertEquals($res->getStatusCode(), 422);
370370
}
371+
372+
public function testWithAccessor(): void
373+
{
374+
$res = $this->get('/api/with_accessors/1', ['Accept' => ['application/ld+json']]);
375+
$this->assertArraySubset(['name' => 'test'], $res->json());
376+
}
371377
}

0 commit comments

Comments
 (0)