Skip to content

Commit

Permalink
Merge 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 24, 2024
2 parents 1ac0c3d + ac6f667 commit a4d6ac4
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 133 deletions.
31 changes: 14 additions & 17 deletions features/hydra/docs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ Feature: Documentation support
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
# Context
And the JSON node "@context.@vocab" should be equal to "http://example.com/docs.jsonld#"
And the JSON node "@context.hydra" should be equal to "http://www.w3.org/ns/hydra/core#"
And the JSON node "@context.rdf" should be equal to "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
And the JSON node "@context.rdfs" should be equal to "http://www.w3.org/2000/01/rdf-schema#"
And the JSON node "@context.xmls" should be equal to "http://www.w3.org/2001/XMLSchema#"
And the JSON node "@context.owl" should be equal to "http://www.w3.org/2002/07/owl#"
And the JSON node "@context.domain.@id" should be equal to "rdfs:domain"
And the JSON node "@context.domain.@type" should be equal to "@id"
And the JSON node "@context.range.@id" should be equal to "rdfs:range"
And the JSON node "@context.range.@type" should be equal to "@id"
And the JSON node "@context.subClassOf.@id" should be equal to "rdfs:subClassOf"
And the JSON node "@context.subClassOf.@type" should be equal to "@id"
And the JSON node "@context.expects.@id" should be equal to "hydra:expects"
And the JSON node "@context.expects.@type" should be equal to "@id"
And the JSON node "@context.returns.@id" should be equal to "hydra:returns"
And the JSON node "@context.returns.@type" should be equal to "@id"
And the JSON node "@context[0]" should be equal to "http://www.w3.org/ns/hydra/context.jsonld"
And the JSON node "@context[1].@vocab" should be equal to "http://example.com/docs.jsonld#"
And the JSON node "@context[1].hydra" should be equal to "http://www.w3.org/ns/hydra/core#"
And the JSON node "@context[1].rdf" should be equal to "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
And the JSON node "@context[1].rdfs" should be equal to "http://www.w3.org/2000/01/rdf-schema#"
And the JSON node "@context[1].xmls" should be equal to "http://www.w3.org/2001/XMLSchema#"
And the JSON node "@context[1].owl" should be equal to "http://www.w3.org/2002/07/owl#"
And the JSON node "@context[1].domain.@id" should be equal to "rdfs:domain"
And the JSON node "@context[1].domain.@type" should be equal to "@id"
And the JSON node "@context[1].range.@id" should be equal to "rdfs:range"
And the JSON node "@context[1].range.@type" should be equal to "@id"
And the JSON node "@context[1].subClassOf.@id" should be equal to "rdfs:subClassOf"
And the JSON node "@context[1].subClassOf.@type" should be equal to "@id"
# Root properties
And the JSON node "@id" should be equal to "/docs.jsonld"
And the JSON node "hydra:title" should be equal to "My Dummy API"
Expand Down Expand Up @@ -79,7 +76,7 @@ Feature: Documentation support
And the value of the node "hydra:method" of the operation "GET" of the Hydra class "Dummy" is "GET"
And the value of the node "hydra:title" of the operation "GET" of the Hydra class "Dummy" is "Retrieves a Dummy resource."
And the value of the node "rdfs:label" of the operation "GET" of the Hydra class "Dummy" is "Retrieves a Dummy resource."
And the value of the node "returns" of the operation "GET" of the Hydra class "Dummy" is "#Dummy"
And the value of the node "returns" of the operation "GET" of the Hydra class "Dummy" is "Dummy"
And the value of the node "hydra:title" of the operation "PUT" of the Hydra class "Dummy" is "Replaces the Dummy resource."
And the value of the node "hydra:title" of the operation "DELETE" of the Hydra class "Dummy" is "Deletes the Dummy resource."
And the value of the node "returns" of the operation "DELETE" of the Hydra class "Dummy" is "owl:Nothing"
Expand Down
31 changes: 16 additions & 15 deletions src/Hydra/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function normalize(mixed $object, ?string $format = null, array $context
}

$shortName = $resourceMetadata->getShortName();

$prefixedShortName = $resourceMetadata->getTypes()[0] ?? "#$shortName";
$this->populateEntrypointProperties($resourceMetadata, $shortName, $prefixedShortName, $entrypointProperties, $hydraPrefix, $resourceMetadataCollection);
$classes[] = $this->getClass($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $context, $hydraPrefix, $resourceMetadataCollection);
Expand Down Expand Up @@ -243,8 +244,7 @@ private function getHydraOperations(bool $collection, ?ResourceMetadataCollectio
if (('POST' === $operation->getMethod() || $operation instanceof CollectionOperationInterface) !== $collection) {
continue;
}

$hydraOperations[] = $this->getHydraOperation($operation, $operation->getTypes()[0] ?? "#{$operation->getShortName()}", $hydraPrefix);
$hydraOperations[] = $this->getHydraOperation($operation, $operation->getShortName(), $hydraPrefix);
}
}

Expand Down Expand Up @@ -430,7 +430,7 @@ private function getClasses(array $entrypointProperties, array $classes, string
'@type' => $hydraPrefix.'Operation',
$hydraPrefix.'method' => 'GET',
'rdfs:label' => 'The API entrypoint.',
'returns' => '#EntryPoint',
'returns' => 'EntryPoint',
],
];

Expand Down Expand Up @@ -573,18 +573,19 @@ private function computeDoc(Documentation $object, array $classes, string $hydra
private function getContext(string $hydraPrefix = ContextBuilder::HYDRA_PREFIX): array
{
return [
'@vocab' => $this->urlGenerator->generate('api_doc', ['_format' => self::FORMAT], UrlGeneratorInterface::ABS_URL).'#',
'hydra' => ContextBuilderInterface::HYDRA_NS,
'rdf' => ContextBuilderInterface::RDF_NS,
'rdfs' => ContextBuilderInterface::RDFS_NS,
'xmls' => ContextBuilderInterface::XML_NS,
'owl' => ContextBuilderInterface::OWL_NS,
'schema' => ContextBuilderInterface::SCHEMA_ORG_NS,
'domain' => ['@id' => 'rdfs:domain', '@type' => '@id'],
'range' => ['@id' => 'rdfs:range', '@type' => '@id'],
'subClassOf' => ['@id' => 'rdfs:subClassOf', '@type' => '@id'],
'expects' => ['@id' => $hydraPrefix.'expects', '@type' => '@id'],
'returns' => ['@id' => $hydraPrefix.'returns', '@type' => '@id'],
ContextBuilderInterface::HYDRA_CONTEXT,
[
'@vocab' => $this->urlGenerator->generate('api_doc', ['_format' => self::FORMAT], UrlGeneratorInterface::ABS_URL).'#',
'hydra' => ContextBuilderInterface::HYDRA_NS,
'rdf' => ContextBuilderInterface::RDF_NS,
'rdfs' => ContextBuilderInterface::RDFS_NS,
'xmls' => ContextBuilderInterface::XML_NS,
'owl' => ContextBuilderInterface::OWL_NS,
'schema' => ContextBuilderInterface::SCHEMA_ORG_NS,
'domain' => ['@id' => 'rdfs:domain', '@type' => '@id'],
'range' => ['@id' => 'rdfs:range', '@type' => '@id'],
'subClassOf' => ['@id' => 'rdfs:subClassOf', '@type' => '@id'],
],
];
}

Expand Down
Loading

0 comments on commit a4d6ac4

Please sign in to comment.