Skip to content

Commit 97db06a

Browse files
fix(hydra): store and use hydra context as static asset
1 parent 001d771 commit 97db06a

File tree

7 files changed

+14
-8
lines changed

7 files changed

+14
-8
lines changed

features/hydra/docs.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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[0]" should be equal to "http://www.w3.org/ns/hydra/context.jsonld"
16+
And the JSON node "@context[0]" should be equal to "/bundles/apiplatform/hydra/context.jsonld"
1717
And the JSON node "@context[1].@vocab" should be equal to "http://example.com/docs.jsonld#"
1818
And the JSON node "@context[1].hydra" should be equal to "http://www.w3.org/ns/hydra/core#"
1919
And the JSON node "@context[1].rdf" should be equal to "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

src/Hydra/Serializer/DocumentationNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ private function computeDoc(Documentation $object, array $classes, string $hydra
573573
private function getContext(string $hydraPrefix = ContextBuilder::HYDRA_PREFIX): array
574574
{
575575
return [
576-
ContextBuilderInterface::HYDRA_CONTEXT,
576+
'/bundles/apiplatform/hydra/context.jsonld',
577577
[
578578
'@vocab' => $this->urlGenerator->generate('api_doc', ['_format' => self::FORMAT], UrlGeneratorInterface::ABS_URL).'#',
579579
'hydra' => ContextBuilderInterface::HYDRA_NS,

src/Hydra/Tests/Serializer/DocumentationNormalizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function doTestNormalize($resourceMetadataFactory = null): void
106106

107107
$expected = [
108108
'@context' => [
109-
'http://www.w3.org/ns/hydra/context.jsonld',
109+
'/bundles/apiplatform/hydra/context.jsonld',
110110
[
111111
'@vocab' => '/doc#',
112112
'hydra' => 'http://www.w3.org/ns/hydra/core#',
@@ -406,7 +406,7 @@ public function testNormalizeInputOutputClass(): void
406406

407407
$expected = [
408408
'@context' => [
409-
'http://www.w3.org/ns/hydra/context.jsonld',
409+
'/bundles/apiplatform/hydra/context.jsonld',
410410
[
411411
'@vocab' => '/doc#',
412412
'hydra' => 'http://www.w3.org/ns/hydra/core#',
@@ -766,7 +766,7 @@ public function testNormalizeWithoutPrefix(): void
766766

767767
$expected = [
768768
'@context' => [
769-
'http://www.w3.org/ns/hydra/context.jsonld',
769+
'/bundles/apiplatform/hydra/context.jsonld',
770770
[
771771
'@vocab' => '/doc#',
772772
'hydra' => 'http://www.w3.org/ns/hydra/core#',

src/JsonLd/ContextBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private function getResourceContextWithShortname(string $resourceClass, int $ref
185185
}
186186

187187
if (false === ($this->defaultContext[self::HYDRA_CONTEXT_HAS_PREFIX] ?? true)) {
188-
return [ContextBuilderInterface::HYDRA_CONTEXT, $context];
188+
return ['/bundles/apiplatform/hydra/context.jsonld', $context];
189189
}
190190

191191
return $context;

src/JsonLd/ContextBuilderInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424
interface ContextBuilderInterface
2525
{
26-
public const HYDRA_CONTEXT = 'http://www.w3.org/ns/hydra/context.jsonld';
2726
public const HYDRA_NS = 'http://www.w3.org/ns/hydra/core#';
2827
public const JSONLD_NS = 'http://www.w3.org/ns/json-ld#';
2928
public const RDF_NS = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';

tests/JsonLd/ContextBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public function testResourceContextWithoutHydraPrefix(): void
291291
$contextBuilder = new ContextBuilder($this->resourceNameCollectionFactoryProphecy->reveal(), $this->resourceMetadataCollectionFactoryProphecy->reveal(), $this->propertyNameCollectionFactoryProphecy->reveal(), $this->propertyMetadataFactoryProphecy->reveal(), $this->urlGeneratorProphecy->reveal(), null, null, [ContextBuilder::HYDRA_CONTEXT_HAS_PREFIX => false]);
292292

293293
$expected = [
294-
'http://www.w3.org/ns/hydra/context.jsonld',
294+
'/bundles/apiplatform/hydra/context.jsonld',
295295
[
296296
'@vocab' => '#',
297297
'hydra' => 'http://www.w3.org/ns/hydra/core#',

update-js.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,12 @@ fi
9494
mkdir -p "$dest"
9595
cp node_modules/redoc/bundles/redoc.standalone.js "$dest"
9696

97+
dest=src/Symfony/Bundle/Resources/public/hydra/
98+
if [[ -d "$dest" ]]; then
99+
rm -Rf "$dest"
100+
fi
101+
mkdir -p "$dest"
102+
curl -L -A "Mozilla/5.0" -o "${dest}context.jsonld" http://www.w3.org/ns/hydra/context.jsonld
103+
97104
rm -Rf package.json node_modules/
98105
# TODO Laravel public files

0 commit comments

Comments
 (0)