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
7 changes: 1 addition & 6 deletions features/hydra/docs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ Feature: Documentation support
# Context
And the Hydra context matches the online resource "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"
Expand Down Expand Up @@ -63,7 +58,7 @@ Feature: Documentation support
And the value of the node "hydra:property.@type" of the property "name" of the Hydra class "Dummy" is "rdf:Property"
And the value of the node "hydra:property.label" of the property "name" of the Hydra class "Dummy" is "name"
And the value of the node "hydra:property.domain" of the property "name" of the Hydra class "Dummy" is "#Dummy"
And the value of the node "hydra:property.range" of the property "name" of the Hydra class "Dummy" is "xmls:string"
And the value of the node "hydra:property.range" of the property "name" of the Hydra class "Dummy" is "xsd:string"
And the value of the node "hydra:property.range" of the property "relatedDummy" of the Hydra class "Dummy" is "https://schema.org/Product"
And the value of the node "hydra:property.owl:maxCardinality" of the property "relatedDummy" of the Hydra class "Dummy" is "1"
And the value of the node "hydra:property.range" of the property "relatedDummies" of the Hydra class "Dummy" is "https://schema.org/Product"
Expand Down
39 changes: 17 additions & 22 deletions src/Hydra/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,23 +380,23 @@ private function getRange(ApiProperty $propertyMetadata): array|string|null
}

if ($nativeType->isIdentifiedBy(TypeIdentifier::STRING)) {
$types[] = 'xmls:string';
$types[] = 'xsd:string';
}

if ($nativeType->isIdentifiedBy(TypeIdentifier::INT)) {
$types[] = 'xmls:integer';
$types[] = 'xsd:integer';
}

if ($nativeType->isIdentifiedBy(TypeIdentifier::FLOAT)) {
$types[] = 'xmls:decimal';
$types[] = 'xsd:decimal';
}

if ($nativeType->isIdentifiedBy(TypeIdentifier::BOOL)) {
$types[] = 'xmls:boolean';
$types[] = 'xsd:boolean';
}

if ($nativeType->isIdentifiedBy(\DateTimeInterface::class)) {
$types[] = 'xmls:dateTime';
$types[] = 'xsd:dateTime';
}

/** @var class-string|null $className */
Expand Down Expand Up @@ -429,23 +429,23 @@ private function getRange(ApiProperty $propertyMetadata): array|string|null

switch ($type->getBuiltinType()) {
case LegacyType::BUILTIN_TYPE_STRING:
if (!\in_array('xmls:string', $types, true)) {
$types[] = 'xmls:string';
if (!\in_array('xsd:string', $types, true)) {
$types[] = 'xsd:string';
}
break;
case LegacyType::BUILTIN_TYPE_INT:
if (!\in_array('xmls:integer', $types, true)) {
$types[] = 'xmls:integer';
if (!\in_array('xsd:integer', $types, true)) {
$types[] = 'xsd:integer';
}
break;
case LegacyType::BUILTIN_TYPE_FLOAT:
if (!\in_array('xmls:decimal', $types, true)) {
$types[] = 'xmls:decimal';
if (!\in_array('xsd:decimal', $types, true)) {
$types[] = 'xsd:decimal';
}
break;
case LegacyType::BUILTIN_TYPE_BOOL:
if (!\in_array('xmls:boolean', $types, true)) {
$types[] = 'xmls:boolean';
if (!\in_array('xsd:boolean', $types, true)) {
$types[] = 'xsd:boolean';
}
break;
case LegacyType::BUILTIN_TYPE_OBJECT:
Expand All @@ -454,8 +454,8 @@ private function getRange(ApiProperty $propertyMetadata): array|string|null
}

if (is_a($className, \DateTimeInterface::class, true)) {
if (!\in_array('xmls:dateTime', $types, true)) {
$types[] = 'xmls:dateTime';
if (!\in_array('xsd:dateTime', $types, true)) {
$types[] = 'xsd:dateTime';
}
break;
}
Expand Down Expand Up @@ -557,7 +557,7 @@ private function getClasses(array $entrypointProperties, array $classes, string
'@type' => 'rdf:Property',
'rdfs:label' => 'propertyPath',
'domain' => '#ConstraintViolationList',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
$hydraPrefix.'title' => 'propertyPath',
$hydraPrefix.'description' => 'The property path of the violation',
Expand All @@ -571,7 +571,7 @@ private function getClasses(array $entrypointProperties, array $classes, string
'@type' => 'rdf:Property',
'rdfs:label' => 'message',
'domain' => '#ConstraintViolationList',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
$hydraPrefix.'title' => 'message',
$hydraPrefix.'description' => 'The message associated with the violation',
Expand Down Expand Up @@ -664,11 +664,6 @@ private function getContext(string $hydraPrefix = ContextBuilder::HYDRA_PREFIX):
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'],
Expand Down
45 changes: 15 additions & 30 deletions src/Hydra/Tests/Serializer/DocumentationNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ private function doTestNormalize($resourceMetadataFactory = null): void
HYDRA_CONTEXT,
[
'@vocab' => '/doc#',
'hydra' => 'http://www.w3.org/ns/hydra/core#',
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
'xmls' => 'http://www.w3.org/2001/XMLSchema#',
'owl' => 'http://www.w3.org/2002/07/owl#',
'schema' => 'https://schema.org/',
'domain' => [
'@id' => 'rdfs:domain',
Expand Down Expand Up @@ -151,7 +146,7 @@ private function doTestNormalize($resourceMetadataFactory = null): void
'@type' => 'rdf:Property',
'label' => 'name',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'hydra:title' => 'name',
'hydra:required' => false,
Expand Down Expand Up @@ -181,7 +176,7 @@ private function doTestNormalize($resourceMetadataFactory = null): void
'@type' => 'rdf:Property',
'label' => 'name_converted',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'hydra:title' => 'name_converted',
'hydra:required' => false,
Expand Down Expand Up @@ -310,7 +305,7 @@ private function doTestNormalize($resourceMetadataFactory = null): void
'@type' => 'rdf:Property',
'rdfs:label' => 'propertyPath',
'domain' => '#ConstraintViolationList',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'hydra:title' => 'propertyPath',
'hydra:description' => 'The property path of the violation',
Expand All @@ -324,7 +319,7 @@ private function doTestNormalize($resourceMetadataFactory = null): void
'@type' => 'rdf:Property',
'rdfs:label' => 'message',
'domain' => '#ConstraintViolationList',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'hydra:title' => 'message',
'hydra:description' => 'The message associated with the violation',
Expand Down Expand Up @@ -400,7 +395,7 @@ public function testNormalizeInputOutputClass(): void
'@type' => 'rdf:Property',
'label' => 'a',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'hydra:title' => 'a',
'hydra:required' => false,
Expand All @@ -415,7 +410,7 @@ public function testNormalizeInputOutputClass(): void
'@type' => 'rdf:Property',
'label' => 'b',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'hydra:title' => 'b',
'hydra:required' => false,
Expand All @@ -430,7 +425,7 @@ public function testNormalizeInputOutputClass(): void
'@type' => 'rdf:Property',
'label' => 'c',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'hydra:title' => 'c',
'hydra:required' => false,
Expand All @@ -445,7 +440,7 @@ public function testNormalizeInputOutputClass(): void
'@type' => 'rdf:Property',
'label' => 'd',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'hydra:title' => 'd',
'hydra:required' => false,
Expand Down Expand Up @@ -536,7 +531,7 @@ public function testHasHydraContext(): void
'@type' => 'https://schema.org/Enumeration',
'label' => 'name',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
], $documentationNormalizer->normalize($documentation)['hydra:supportedClass'][0]['hydra:supportedProperty'][0]['hydra:property']);
}

Expand Down Expand Up @@ -600,11 +595,6 @@ public function testNormalizeWithoutPrefix(): void
HYDRA_CONTEXT,
[
'@vocab' => '/doc#',
'hydra' => 'http://www.w3.org/ns/hydra/core#',
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
'xmls' => 'http://www.w3.org/2001/XMLSchema#',
'owl' => 'http://www.w3.org/2002/07/owl#',
'schema' => 'https://schema.org/',
'domain' => [
'@id' => 'rdfs:domain',
Expand Down Expand Up @@ -638,7 +628,7 @@ public function testNormalizeWithoutPrefix(): void
'@type' => 'rdf:Property',
'label' => 'name',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'title' => 'name',
'required' => false,
Expand Down Expand Up @@ -668,7 +658,7 @@ public function testNormalizeWithoutPrefix(): void
'@type' => 'rdf:Property',
'label' => 'name_converted',
'domain' => '#dummy',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'title' => 'name_converted',
'required' => false,
Expand Down Expand Up @@ -797,7 +787,7 @@ public function testNormalizeWithoutPrefix(): void
'@type' => 'rdf:Property',
'rdfs:label' => 'propertyPath',
'domain' => '#ConstraintViolationList',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'title' => 'propertyPath',
'description' => 'The property path of the violation',
Expand All @@ -811,7 +801,7 @@ public function testNormalizeWithoutPrefix(): void
'@type' => 'rdf:Property',
'rdfs:label' => 'message',
'domain' => '#ConstraintViolationList',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'title' => 'message',
'description' => 'The message associated with the violation',
Expand Down Expand Up @@ -862,11 +852,6 @@ public function testNormalizeNoEntrypointAndHideHydraOperation(): void
HYDRA_CONTEXT,
[
'@vocab' => '/doc#',
'hydra' => 'http://www.w3.org/ns/hydra/core#',
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#',
'xmls' => 'http://www.w3.org/2001/XMLSchema#',
'owl' => 'http://www.w3.org/2002/07/owl#',
'schema' => 'https://schema.org/',
'domain' => [
'@id' => 'rdfs:domain',
Expand Down Expand Up @@ -900,7 +885,7 @@ public function testNormalizeNoEntrypointAndHideHydraOperation(): void
'@type' => 'rdf:Property',
'rdfs:label' => 'propertyPath',
'domain' => '#ConstraintViolationList',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'title' => 'propertyPath',
'description' => 'The property path of the violation',
Expand All @@ -914,7 +899,7 @@ public function testNormalizeNoEntrypointAndHideHydraOperation(): void
'@type' => 'rdf:Property',
'rdfs:label' => 'message',
'domain' => '#ConstraintViolationList',
'range' => 'xmls:string',
'range' => 'xsd:string',
],
'title' => 'message',
'description' => 'The message associated with the violation',
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestBundle/Document/RelationEmbedder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[ApiResource(operations: [new Get(), new Put(extraProperties: ['standard_put' => false]), new Delete(), new Get(routeName: 'relation_embedded.custom_get'), new Get(uriTemplate: '/api/custom-call/{id}'), new Put(uriTemplate: '/api/custom-call/{id}'), new Post(), new GetCollection()], normalizationContext: ['groups' => ['barcelona']], denormalizationContext: ['groups' => ['chicago']], hydraContext: ['@type' => 'hydra:Operation', 'hydra:title' => 'A custom operation', 'returns' => 'xmls:string'])]
#[ApiResource(operations: [new Get(), new Put(extraProperties: ['standard_put' => false]), new Delete(), new Get(routeName: 'relation_embedded.custom_get'), new Get(uriTemplate: '/api/custom-call/{id}'), new Put(uriTemplate: '/api/custom-call/{id}'), new Post(), new GetCollection()], normalizationContext: ['groups' => ['barcelona']], denormalizationContext: ['groups' => ['chicago']], hydraContext: ['@type' => 'hydra:Operation', 'hydra:title' => 'A custom operation', 'returns' => 'xsd:string'])]
#[ODM\Document]
class RelationEmbedder
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestBundle/Entity/RelationEmbedder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[ApiResource(operations: [new Get(), new Put(extraProperties: ['standard_put' => false]), new Delete(), new Get(routeName: 'relation_embedded.custom_get'), new Get(uriTemplate: '/api/custom-call/{id}'), new Put(uriTemplate: '/api/custom-call/{id}'), new Post(), new GetCollection()], normalizationContext: ['groups' => ['barcelona']], denormalizationContext: ['groups' => ['chicago']], hydraContext: ['@type' => 'hydra:Operation', 'hydra:title' => 'A custom operation', 'returns' => 'xmls:string'])]
#[ApiResource(operations: [new Get(), new Put(extraProperties: ['standard_put' => false]), new Delete(), new Get(routeName: 'relation_embedded.custom_get'), new Get(uriTemplate: '/api/custom-call/{id}'), new Put(uriTemplate: '/api/custom-call/{id}'), new Post(), new GetCollection()], normalizationContext: ['groups' => ['barcelona']], denormalizationContext: ['groups' => ['chicago']], hydraContext: ['@type' => 'hydra:Operation', 'hydra:title' => 'A custom operation', 'returns' => 'xsd:string'])]
#[ORM\Entity]
class RelationEmbedder
{
Expand Down
Loading