Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/Hydra/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,15 @@ private function populateEntrypointProperties(string $resourceClass, ResourceMet
'@type' => 'hydra:Link',
'domain' => '#Entrypoint',
'rdfs:label' => "The collection of $shortName resources",
'range' => 'hydra:PagedCollection',
'rdfs:range' => [
'hydra:PagedCollection',
[
'owl:equivalentClass' => [
'owl:onProperty' => 'hydra:member',
'owl:allValuesFrom' => "#$shortName",
],
],
],
'hydra:supportedOperation' => $hydraCollectionOperations,
],
'hydra:title' => "The collection of $shortName resources",
Expand Down Expand Up @@ -423,14 +431,22 @@ private function getClasses(array $entrypointProperties, array $classes): array
*/
private function getProperty(PropertyMetadata $propertyMetadata, string $propertyName, string $prefixedShortName, string $shortName): array
{
$propertyData = [
'@id' => $propertyMetadata->getIri() ?? "#$shortName/$propertyName",
'@type' => $propertyMetadata->isReadableLink() ? 'rdf:Property' : 'hydra:Link',
'rdfs:label' => $propertyName,
'domain' => $prefixedShortName,
];

$type = $propertyMetadata->getType();

if (null !== $type && !$type->isCollection() && (null !== $className = $type->getClassName()) && $this->resourceClassResolver->isResourceClass($className)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part really necessary (null !== $className = $type->getClassName()) && $this->resourceClassResolver->isResourceClass($className)?
Even if it is not a resource, the max cardinality is 1 if it's not a collection isn't it?

$propertyData['owl:maxCardinality'] = 1;
}

$property = [
'@type' => 'hydra:SupportedProperty',
'hydra:property' => [
'@id' => $propertyMetadata->getIri() ?? "#$shortName/$propertyName",
'@type' => $propertyMetadata->isReadableLink() ? 'rdf:Property' : 'hydra:Link',
'rdfs:label' => $propertyName,
'domain' => $prefixedShortName,
],
'hydra:property' => $propertyData,
'hydra:title' => $propertyName,
'hydra:required' => $propertyMetadata->isRequired(),
'hydra:readable' => $propertyMetadata->isReadable(),
Expand Down
10 changes: 9 additions & 1 deletion tests/Hydra/Serializer/DocumentationNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,15 @@ public function testNormalize()
'@type' => 'hydra:Link',
'rdfs:label' => 'The collection of dummy resources',
'domain' => '#Entrypoint',
'range' => 'hydra:PagedCollection',
'rdfs:range' => [
'hydra:PagedCollection',
[
'owl:equivalentClass' => [
'owl:onProperty' => 'hydra:member',
'owl:allValuesFrom' => '#dummy',
],
],
],
'hydra:supportedOperation' => [
0 => [
'@type' => 'hydra:Operation',
Expand Down