Skip to content

Commit bb29bab

Browse files
committed
fix(metadata): generate skolem IRI by default
1 parent f0995c3 commit bb29bab

File tree

6 files changed

+20
-32
lines changed

6 files changed

+20
-32
lines changed

features/jsonld/non_resource.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Feature: JSON-LD non-resource handling
3838
}
3939
}
4040
"""
41-
And the JSON node "notAResource.@id" should not exist
41+
And the JSON node "notAResource.@id" should exist
4242

4343
Scenario: Get a resource containing a raw object with selected properties
4444
Given there are 1 dummy objects with relatedDummy and its thirdLevel

src/JsonLd/Serializer/ObjectNormalizer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\JsonLd\Serializer;
1515

16-
use ApiPlatform\Api\IriConverterInterface;
1716
use ApiPlatform\JsonLd\AnonymousContextBuilderInterface;
1817
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
1918
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@@ -28,7 +27,7 @@ final class ObjectNormalizer implements NormalizerInterface, CacheableSupportsMe
2827

2928
public const FORMAT = 'jsonld';
3029

31-
public function __construct(private readonly NormalizerInterface $decorated, private readonly IriConverterInterface $iriConverter, private AnonymousContextBuilderInterface $anonymousContextBuilder)
30+
public function __construct(private readonly NormalizerInterface $decorated, private AnonymousContextBuilderInterface $anonymousContextBuilder)
3231
{
3332
}
3433

src/Serializer/AbstractItemNormalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ protected function getAttributeValue(object $object, string $attribute, string $
592592
if ($type && $type->getClassName()) {
593593
$childContext = $this->createChildContext($context, $attribute, $format);
594594
unset($childContext['iri'], $childContext['uri_variables']);
595-
$childContext['output']['gen_id'] = $propertyMetadata->getGenId() ?? false;
595+
$childContext['output']['gen_id'] = $propertyMetadata->getGenId() ?? true;
596596

597597
return $this->serializer->normalize($attributeValue, $format, $childContext);
598598
}

src/Symfony/Bundle/Resources/config/jsonld.xml

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
<service id="api_platform.jsonld.normalizer.object" class="ApiPlatform\JsonLd\Serializer\ObjectNormalizer" public="false">
3838
<argument type="service" id="serializer.normalizer.object" />
39-
<argument type="service" id="api_platform.iri_converter" />
4039
<argument type="service" id="api_platform.jsonld.context_builder" />
4140

4241
<!-- Run after serializer.denormalizer.array but before serializer.normalizer.object -->

tests/Fixtures/TestBundle/Entity/JsonSchemaContextDummy.php

+17-23
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,37 @@
1313

1414
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;
1515

16-
use ApiPlatform\Core\Annotation\ApiProperty;
17-
use ApiPlatform\Core\Annotation\ApiResource;
16+
use ApiPlatform\Metadata\ApiProperty;
17+
use ApiPlatform\Metadata\ApiResource;
1818
use Doctrine\ORM\Mapping as ORM;
1919

2020
/**
2121
* JSON Schema Context Dummy.
22-
*
23-
* @ApiResource
24-
*
25-
* @ORM\Entity
2622
*/
23+
#[ORM\Entity]
24+
#[ApiResource]
2725
class JsonSchemaContextDummy
2826
{
2927
/**
3028
* @var int The id
31-
*
32-
* @ApiProperty(identifier=true)
33-
* @ORM\Column(type="integer")
34-
* @ORM\Id
35-
* @ORM\GeneratedValue(strategy="AUTO")
3629
*/
37-
private $id;
30+
#[ApiProperty(identifier: true)]
31+
#[ORM\Column(type: 'integer')]
32+
#[ORM\Id]
33+
#[ORM\GeneratedValue(strategy: 'AUTO')]
34+
public $id;
3835

3936
/**
4037
* @var array
41-
*
42-
* @ApiProperty(
43-
* attributes={
44-
* "json_schema_context"={
45-
* "type"="array",
46-
* "items"={"type"="string"},
47-
* "minItems"=2,
48-
* "maxItems"=2
49-
* }
50-
* },
51-
* )
5238
*/
39+
#[ApiProperty(
40+
jsonSchemaContext: [
41+
'type' => 'array',
42+
'items' => ['type' => 'string'],
43+
'minItems' => 2,
44+
'maxItems' => 2,
45+
]
46+
)]
5347
private $things = ['pool', 'bag'];
5448

5549
public function getId()

tests/JsonLd/Serializer/ObjectNormalizerTest.php

-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function testNormalize(): void
5050

5151
$normalizer = new ObjectNormalizer(
5252
$serializerProphecy->reveal(), // @phpstan-ignore-line
53-
$iriConverterProphecy->reveal(),
5453
$contextBuilderProphecy->reveal()
5554
);
5655

@@ -79,7 +78,6 @@ public function testNormalizeEmptyArray(): void
7978

8079
$normalizer = new ObjectNormalizer(
8180
$serializerProphecy->reveal(), // @phpstan-ignore-line
82-
$iriConverterProphecy->reveal(),
8381
$contextBuilderProphecy->reveal()
8482
);
8583

@@ -103,7 +101,6 @@ public function testNormalizeWithOutput(): void
103101

104102
$normalizer = new ObjectNormalizer(
105103
$serializerProphecy->reveal(), // @phpstan-ignore-line
106-
$iriConverterProphecy->reveal(),
107104
$contextBuilderProphecy->reveal()
108105
);
109106

@@ -133,7 +130,6 @@ public function testNormalizeWithContext(): void
133130

134131
$normalizer = new ObjectNormalizer(
135132
$serializerProphecy->reveal(), // @phpstan-ignore-line
136-
$iriConverterProphecy->reveal(),
137133
$contextBuilderProphecy->reveal()
138134
);
139135

0 commit comments

Comments
 (0)