Skip to content

Commit 77ade2a

Browse files
authored
Merge pull request #900 from dunglas/fix_hydra
Fix range in the Hydra doc when the relation has an IRI
2 parents baffb81 + b0e865f commit 77ade2a

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

features/hydra/docs.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Feature: Documentation support
6565
And the value of the node "hydra:property.rdfs:label" of the property "name" of the Hydra class "Dummy" is "name"
6666
And the value of the node "hydra:property.domain" of the property "name" of the Hydra class "Dummy" is "#Dummy"
6767
And the value of the node "hydra:property.range" of the property "name" of the Hydra class "Dummy" is "xmls:string"
68+
And the value of the node "hydra:property.range" of the property "relatedDummy" of the Hydra class "Dummy" is "https://schema.org/Product"
69+
And the value of the node "hydra:property.range" of the property "relatedDummies" of the Hydra class "Dummy" is "https://schema.org/Product"
6870
And the value of the node "hydra:title" of the property "name" of the Hydra class "Dummy" is "name"
6971
And the value of the node "hydra:description" of the property "name" of the Hydra class "Dummy" is "The dummy name"
7072
# Operations

src/Hydra/Serializer/DocumentationNormalizer.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function normalize($object, $format = null, array $context = [])
6161
foreach ($object->getResourceNameCollection() as $resourceClass) {
6262
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
6363
$shortName = $resourceMetadata->getShortName();
64-
$prefixedShortName = (null === $iri = $resourceMetadata->getIri()) ? '#'.$shortName : $iri;
64+
$prefixedShortName = $resourceMetadata->getIri() ?? "#$shortName";
6565

6666
$this->populateEntrypointProperties($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $entrypointProperties);
6767
$classes[] = $this->getClass($resourceClass, $resourceMetadata, $shortName, $prefixedShortName);
@@ -92,11 +92,11 @@ private function populateEntrypointProperties(string $resourceClass, ResourceMet
9292
'@id' => sprintf('#Entrypoint/%s', lcfirst($shortName)),
9393
'@type' => 'hydra:Link',
9494
'domain' => '#Entrypoint',
95-
'rdfs:label' => sprintf('The collection of %s resources', $shortName),
95+
'rdfs:label' => "The collection of $shortName resources",
9696
'range' => 'hydra:PagedCollection',
9797
'hydra:supportedOperation' => $hydraCollectionOperations,
9898
],
99-
'hydra:title' => sprintf('The collection of %s resources', $shortName),
99+
'hydra:title' => "The collection of $shortName resources",
100100
'hydra:readable' => true,
101101
'hydra:writable' => false,
102102
];
@@ -231,31 +231,31 @@ private function getHydraOperation(string $resourceClass, ResourceMetadata $reso
231231

232232
if ('GET' === $method && $collection) {
233233
$hydraOperation = [
234-
'hydra:title' => sprintf('Retrieves the collection of %s resources.', $shortName),
234+
'hydra:title' => "Retrieves the collection of $shortName resources.",
235235
'returns' => 'hydra:PagedCollection',
236236
] + $hydraOperation;
237237
} elseif ('GET' === $method) {
238238
$hydraOperation = [
239-
'hydra:title' => sprintf('Retrieves %s resource.', $shortName),
239+
'hydra:title' => "Retrieves $shortName resource.",
240240
'returns' => $prefixedShortName,
241241
] + $hydraOperation;
242242
} elseif ('POST' === $method) {
243243
$hydraOperation = [
244244
'@type' => 'hydra:CreateResourceOperation',
245-
'hydra:title' => sprintf('Creates a %s resource.', $shortName),
245+
'hydra:title' => "Creates a $shortName resource.",
246246
'returns' => $prefixedShortName,
247247
'expects' => $prefixedShortName,
248248
] + $hydraOperation;
249249
} elseif ('PUT' === $method) {
250250
$hydraOperation = [
251251
'@type' => 'hydra:ReplaceResourceOperation',
252-
'hydra:title' => sprintf('Replaces the %s resource.', $shortName),
252+
'hydra:title' => "Replaces the $shortName resource.",
253253
'returns' => $prefixedShortName,
254254
'expects' => $prefixedShortName,
255255
] + $hydraOperation;
256256
} elseif ('DELETE' === $method) {
257257
$hydraOperation = [
258-
'hydra:title' => sprintf('Deletes the %s resource.', $shortName),
258+
'hydra:title' => "Deletes the $shortName resource.",
259259
'returns' => 'owl:Nothing',
260260
] + $hydraOperation;
261261
}
@@ -318,7 +318,9 @@ private function getRange(PropertyMetadata $propertyMetadata)
318318
}
319319

320320
if ($this->resourceClassResolver->isResourceClass($className)) {
321-
return sprintf('#%s', $this->resourceMetadataFactory->create($className)->getShortName());
321+
$resourceMetadata = $this->resourceMetadataFactory->create($className);
322+
323+
return $resourceMetadata->getIri() ?? "#{$resourceMetadata->getShortName()}";
322324
}
323325
break;
324326
}
@@ -423,12 +425,11 @@ private function getClasses(array $entrypointProperties, array $classes): array
423425
*/
424426
private function getProperty(PropertyMetadata $propertyMetadata, string $propertyName, string $prefixedShortName, string $shortName): array
425427
{
426-
$type = $propertyMetadata->isReadableLink() ? 'rdf:Property' : 'hydra:Link';
427428
$property = [
428429
'@type' => 'hydra:SupportedProperty',
429430
'hydra:property' => [
430-
'@id' => ($iri = $propertyMetadata->getIri()) ? $iri : sprintf('#%s/%s', $shortName, $propertyName),
431-
'@type' => $type,
431+
'@id' => $propertyMetadata->getIri() ?? "#$shortName/$propertyName",
432+
'@type' => $propertyMetadata->isReadableLink() ? 'rdf:Property' : 'hydra:Link',
432433
'rdfs:label' => $propertyName,
433434
'domain' => $prefixedShortName,
434435
],

0 commit comments

Comments
 (0)