Skip to content

Commit 48db6fa

Browse files
committed
start enum
1 parent 4c5a35f commit 48db6fa

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/Hydra/Serializer/DocumentationNormalizer.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function normalize(mixed $object, ?string $format = null, array $context
5757
$entrypointProperties = [];
5858

5959
foreach ($object->getResourceNameCollection() as $resourceClass) {
60+
if (enum_exists($resourceClass)) {
61+
continue;
62+
}
63+
6064
$resourceMetadataCollection = $this->resourceMetadataFactory->create($resourceClass);
6165

6266
$resourceMetadata = $resourceMetadataCollection[0];
@@ -505,18 +509,10 @@ private function getProperty(ApiProperty $propertyMetadata, string $propertyName
505509
'domain' => $prefixedShortName,
506510
];
507511

508-
if ($propertyMetadata->getDeprecationReason()) {
509-
$propertyData['owl:deprecated'] = true;
510-
}
511-
512512
if ($this->isSingleRelation($propertyMetadata)) {
513513
$propertyData['owl:maxCardinality'] = 1;
514514
}
515515

516-
if (null !== $range = $this->getRange($propertyMetadata)) {
517-
$propertyData['range'] = $range;
518-
}
519-
520516
$property = [
521517
'@type' => 'hydra:SupportedProperty',
522518
'hydra:property' => $propertyData,
@@ -526,10 +522,18 @@ private function getProperty(ApiProperty $propertyMetadata, string $propertyName
526522
'hydra:writeable' => $propertyMetadata->isWritable() || $propertyMetadata->isInitializable(),
527523
];
528524

525+
if (null !== $range = $this->getRange($propertyMetadata)) {
526+
$property['hydra:property']['range'] = $range;
527+
}
528+
529529
if (null !== $description = $propertyMetadata->getDescription()) {
530530
$property['hydra:description'] = $description;
531531
}
532532

533+
if ($propertyMetadata->getDeprecationReason()) {
534+
$property['owl:deprecated'] = true;
535+
}
536+
533537
return $property;
534538
}
535539

@@ -602,3 +606,4 @@ public function hasCacheableSupportsMethod(): bool
602606
return true;
603607
}
604608
}
609+

src/JsonLd/ContextBuilder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ public function getAnonymousResourceContext(object $object, array $context = [],
143143
private function getResourceContextWithShortname(string $resourceClass, int $referenceType, string $shortName, ?HttpOperation $operation = null): array
144144
{
145145
$context = $this->getBaseContext($referenceType);
146+
if (enum_exists($resourceClass)) {
147+
$context['rdfs:label'] = $context['@id'] = $operation->getShortName();
148+
$context['@type'] = 'rdfs:Class';
149+
if ($description = $operation->getDescription()) {
150+
$context['rdfs:comment'] = $description;
151+
}
152+
$context['subClassOf'] = ['@id' => 'schema:Enumeration'];
153+
return $context;
154+
}
155+
146156
$propertyContext = $operation ? ['normalization_groups' => $operation->getNormalizationContext()['groups'] ?? null, 'denormalization_groups' => $operation->getDenormalizationContext()['groups'] ?? null] : ['normalization_groups' => [], 'denormalization_groups' => []];
147157

148158
foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $propertyName) {

0 commit comments

Comments
 (0)