Skip to content

Commit f1da0fe

Browse files
committed
attempt of interface fix
1 parent 573d489 commit f1da0fe

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

features/main/table_inheritance.feature

+35-31
Original file line numberDiff line numberDiff line change
@@ -292,34 +292,38 @@ Feature: Table inheritance
292292
}
293293
"""
294294

295-
# Scenario: Get the parent interface collection
296-
# When I send a "GET" request to "/resource_interfaces"
297-
# Then the response status code should be 200
298-
# And the response should be in JSON
299-
# And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
300-
# And the JSON should be valid according to this schema:
301-
# """
302-
# {
303-
# "type": "object",
304-
# "properties": {
305-
# "hydra:member": {
306-
# "type": "array",
307-
# "items": {
308-
# "type": "object",
309-
# "properties": {
310-
# "@type": {
311-
# "type": "string",
312-
# "pattern": "^ResourceInterface$"
313-
# },
314-
# "foo": {
315-
# "type": "string",
316-
# "required": "true"
317-
# }
318-
# }
319-
# },
320-
# "minItems": 1
321-
# }
322-
# },
323-
# "required": ["hydra:member"]
324-
# }
325-
# """
295+
Scenario: Get the parent interface collection
296+
When I send a "GET" request to "/resource_interfaces"
297+
Then the response status code should be 200
298+
And the response should be in JSON
299+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
300+
And the JSON should be valid according to this schema:
301+
"""
302+
{
303+
"type": "object",
304+
"properties": {
305+
"hydra:member": {
306+
"type": "array",
307+
"items": {
308+
"type": "object",
309+
"properties": {
310+
"@type": {
311+
"type": "string",
312+
"pattern": "^ResourceInterface$"
313+
},
314+
"@id": {
315+
"type": "string",
316+
"pattern": "^_:"
317+
},
318+
"foo": {
319+
"type": "string",
320+
"required": "true"
321+
}
322+
}
323+
},
324+
"minItems": 1
325+
}
326+
},
327+
"required": ["hydra:member"]
328+
}
329+
"""

src/Api/ResourceClassResolver.php

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function getResourceClass($value, string $resourceClass = null, bool $str
5454
return $resourceClass;
5555
}
5656

57+
// The Resource is an interface
58+
if ($value instanceof $resourceClass && $type !== $resourceClass && interface_exists($resourceClass)) {
59+
throw new InvalidArgumentException(sprintf('The given object\'s resource is the interface "%s", finding a class is not possible.', $resourceClass));
60+
}
61+
5762
if (
5863
($isResourceClass ?? $this->isResourceClass($type))
5964
|| (is_subclass_of($type, $resourceClass) && $this->isResourceClass($resourceClass))

src/JsonLd/Serializer/ItemNormalizer.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Core\Api\IriConverterInterface;
1717
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
18+
use ApiPlatform\Core\Api\UrlGeneratorInterface;
1819
use ApiPlatform\Core\Exception\InvalidArgumentException;
1920
use ApiPlatform\Core\JsonLd\ContextBuilderInterface;
2021
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;

0 commit comments

Comments
 (0)