Skip to content

Commit 616146f

Browse files
committed
todo
1 parent 09f248b commit 616146f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/JsonLd/Serializer/ItemNormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,16 @@ public function normalize(mixed $data, ?string $format = null, array $context =
187187
if (!isset($metadata['@type']) && $operation) {
188188
$types = $operation instanceof HttpOperation ? $operation->getTypes() : null;
189189
if (null === $types) {
190-
$types = [$operation->getShortName()];
190+
// TODO: 5.x break on this as this looks wrong, CollectionReferencingItem returns an IRI that point through
191+
// ItemReferencedInCollection but it returns a CollectionReferencingItem therefore we should use the current
192+
// object's class Type and not rely on operation ?
193+
// Use resource-level shortName to avoid operation-specific overrides
194+
$typeClass = $isResourceClass ? $resourceClass : ($operation->getClass() ?? $resourceClass);
195+
try {
196+
$types = [$this->resourceMetadataCollectionFactory->create($typeClass)[0]->getShortName()];
197+
} catch (\Exception) {
198+
$types = [$operation->getShortName()];
199+
}
191200
}
192201
$metadata['@type'] = 1 === \count($types) ? $types[0] : $types;
193202
}

src/Laravel/Routing/IriConverter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ public function getIriFromResource(object|string $resource, int $referenceType =
115115
// This is only for when a class (that is not a resource) extends another one that is a resource, we should remove this behavior
116116
// Skip this if getResourceClassForIri already determined the class via operation stateOptions
117117
if (!\is_string($resource) && $resourceClass === $this->getObjectClass($resource)) {
118-
/** @var class-string $resourceClass */
119118
$resourceClass = $this->getResourceClass($resource, true) ?? $resourceClass;
120119
}
121120

122121
if (!$operation) {
123-
$operation = (new Get())->withClass($resourceClass);
122+
$operation = (new Get())->withClass($resourceClass); // @phpstan-ignore-line
124123
}
125124

126125
if ($operation instanceof HttpOperation && 301 === $operation->getStatus()) {

0 commit comments

Comments
 (0)