Skip to content

Commit a4d6ac4

Browse files
committed
Merge 4.0
2 parents 1ac0c3d + ac6f667 commit a4d6ac4

File tree

6 files changed

+125
-133
lines changed

6 files changed

+125
-133
lines changed

features/hydra/docs.feature

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ Feature: Documentation support
1313
And the response should be in JSON
1414
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
1515
# Context
16-
And the JSON node "@context.@vocab" should be equal to "http://example.com/docs.jsonld#"
17-
And the JSON node "@context.hydra" should be equal to "http://www.w3.org/ns/hydra/core#"
18-
And the JSON node "@context.rdf" should be equal to "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
19-
And the JSON node "@context.rdfs" should be equal to "http://www.w3.org/2000/01/rdf-schema#"
20-
And the JSON node "@context.xmls" should be equal to "http://www.w3.org/2001/XMLSchema#"
21-
And the JSON node "@context.owl" should be equal to "http://www.w3.org/2002/07/owl#"
22-
And the JSON node "@context.domain.@id" should be equal to "rdfs:domain"
23-
And the JSON node "@context.domain.@type" should be equal to "@id"
24-
And the JSON node "@context.range.@id" should be equal to "rdfs:range"
25-
And the JSON node "@context.range.@type" should be equal to "@id"
26-
And the JSON node "@context.subClassOf.@id" should be equal to "rdfs:subClassOf"
27-
And the JSON node "@context.subClassOf.@type" should be equal to "@id"
28-
And the JSON node "@context.expects.@id" should be equal to "hydra:expects"
29-
And the JSON node "@context.expects.@type" should be equal to "@id"
30-
And the JSON node "@context.returns.@id" should be equal to "hydra:returns"
31-
And the JSON node "@context.returns.@type" should be equal to "@id"
16+
And the JSON node "@context[0]" should be equal to "http://www.w3.org/ns/hydra/context.jsonld"
17+
And the JSON node "@context[1].@vocab" should be equal to "http://example.com/docs.jsonld#"
18+
And the JSON node "@context[1].hydra" should be equal to "http://www.w3.org/ns/hydra/core#"
19+
And the JSON node "@context[1].rdf" should be equal to "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
20+
And the JSON node "@context[1].rdfs" should be equal to "http://www.w3.org/2000/01/rdf-schema#"
21+
And the JSON node "@context[1].xmls" should be equal to "http://www.w3.org/2001/XMLSchema#"
22+
And the JSON node "@context[1].owl" should be equal to "http://www.w3.org/2002/07/owl#"
23+
And the JSON node "@context[1].domain.@id" should be equal to "rdfs:domain"
24+
And the JSON node "@context[1].domain.@type" should be equal to "@id"
25+
And the JSON node "@context[1].range.@id" should be equal to "rdfs:range"
26+
And the JSON node "@context[1].range.@type" should be equal to "@id"
27+
And the JSON node "@context[1].subClassOf.@id" should be equal to "rdfs:subClassOf"
28+
And the JSON node "@context[1].subClassOf.@type" should be equal to "@id"
3229
# Root properties
3330
And the JSON node "@id" should be equal to "/docs.jsonld"
3431
And the JSON node "hydra:title" should be equal to "My Dummy API"
@@ -79,7 +76,7 @@ Feature: Documentation support
7976
And the value of the node "hydra:method" of the operation "GET" of the Hydra class "Dummy" is "GET"
8077
And the value of the node "hydra:title" of the operation "GET" of the Hydra class "Dummy" is "Retrieves a Dummy resource."
8178
And the value of the node "rdfs:label" of the operation "GET" of the Hydra class "Dummy" is "Retrieves a Dummy resource."
82-
And the value of the node "returns" of the operation "GET" of the Hydra class "Dummy" is "#Dummy"
79+
And the value of the node "returns" of the operation "GET" of the Hydra class "Dummy" is "Dummy"
8380
And the value of the node "hydra:title" of the operation "PUT" of the Hydra class "Dummy" is "Replaces the Dummy resource."
8481
And the value of the node "hydra:title" of the operation "DELETE" of the Hydra class "Dummy" is "Deletes the Dummy resource."
8582
And the value of the node "returns" of the operation "DELETE" of the Hydra class "Dummy" is "owl:Nothing"

src/Hydra/Serializer/DocumentationNormalizer.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function normalize(mixed $object, ?string $format = null, array $context
7474
}
7575

7676
$shortName = $resourceMetadata->getShortName();
77+
7778
$prefixedShortName = $resourceMetadata->getTypes()[0] ?? "#$shortName";
7879
$this->populateEntrypointProperties($resourceMetadata, $shortName, $prefixedShortName, $entrypointProperties, $hydraPrefix, $resourceMetadataCollection);
7980
$classes[] = $this->getClass($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $context, $hydraPrefix, $resourceMetadataCollection);
@@ -243,8 +244,7 @@ private function getHydraOperations(bool $collection, ?ResourceMetadataCollectio
243244
if (('POST' === $operation->getMethod() || $operation instanceof CollectionOperationInterface) !== $collection) {
244245
continue;
245246
}
246-
247-
$hydraOperations[] = $this->getHydraOperation($operation, $operation->getTypes()[0] ?? "#{$operation->getShortName()}", $hydraPrefix);
247+
$hydraOperations[] = $this->getHydraOperation($operation, $operation->getShortName(), $hydraPrefix);
248248
}
249249
}
250250

@@ -430,7 +430,7 @@ private function getClasses(array $entrypointProperties, array $classes, string
430430
'@type' => $hydraPrefix.'Operation',
431431
$hydraPrefix.'method' => 'GET',
432432
'rdfs:label' => 'The API entrypoint.',
433-
'returns' => '#EntryPoint',
433+
'returns' => 'EntryPoint',
434434
],
435435
];
436436

@@ -573,18 +573,19 @@ private function computeDoc(Documentation $object, array $classes, string $hydra
573573
private function getContext(string $hydraPrefix = ContextBuilder::HYDRA_PREFIX): array
574574
{
575575
return [
576-
'@vocab' => $this->urlGenerator->generate('api_doc', ['_format' => self::FORMAT], UrlGeneratorInterface::ABS_URL).'#',
577-
'hydra' => ContextBuilderInterface::HYDRA_NS,
578-
'rdf' => ContextBuilderInterface::RDF_NS,
579-
'rdfs' => ContextBuilderInterface::RDFS_NS,
580-
'xmls' => ContextBuilderInterface::XML_NS,
581-
'owl' => ContextBuilderInterface::OWL_NS,
582-
'schema' => ContextBuilderInterface::SCHEMA_ORG_NS,
583-
'domain' => ['@id' => 'rdfs:domain', '@type' => '@id'],
584-
'range' => ['@id' => 'rdfs:range', '@type' => '@id'],
585-
'subClassOf' => ['@id' => 'rdfs:subClassOf', '@type' => '@id'],
586-
'expects' => ['@id' => $hydraPrefix.'expects', '@type' => '@id'],
587-
'returns' => ['@id' => $hydraPrefix.'returns', '@type' => '@id'],
576+
ContextBuilderInterface::HYDRA_CONTEXT,
577+
[
578+
'@vocab' => $this->urlGenerator->generate('api_doc', ['_format' => self::FORMAT], UrlGeneratorInterface::ABS_URL).'#',
579+
'hydra' => ContextBuilderInterface::HYDRA_NS,
580+
'rdf' => ContextBuilderInterface::RDF_NS,
581+
'rdfs' => ContextBuilderInterface::RDFS_NS,
582+
'xmls' => ContextBuilderInterface::XML_NS,
583+
'owl' => ContextBuilderInterface::OWL_NS,
584+
'schema' => ContextBuilderInterface::SCHEMA_ORG_NS,
585+
'domain' => ['@id' => 'rdfs:domain', '@type' => '@id'],
586+
'range' => ['@id' => 'rdfs:range', '@type' => '@id'],
587+
'subClassOf' => ['@id' => 'rdfs:subClassOf', '@type' => '@id'],
588+
],
588589
];
589590
}
590591

0 commit comments

Comments
 (0)