Skip to content

Commit

Permalink
fix(metadata): generate skolem IRI by default
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 7, 2022
1 parent f0995c3 commit bb29bab
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
2 changes: 1 addition & 1 deletion features/jsonld/non_resource.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Feature: JSON-LD non-resource handling
}
}
"""
And the JSON node "notAResource.@id" should not exist
And the JSON node "notAResource.@id" should exist

Scenario: Get a resource containing a raw object with selected properties
Given there are 1 dummy objects with relatedDummy and its thirdLevel
Expand Down
3 changes: 1 addition & 2 deletions src/JsonLd/Serializer/ObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace ApiPlatform\JsonLd\Serializer;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\JsonLd\AnonymousContextBuilderInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
Expand All @@ -28,7 +27,7 @@ final class ObjectNormalizer implements NormalizerInterface, CacheableSupportsMe

public const FORMAT = 'jsonld';

public function __construct(private readonly NormalizerInterface $decorated, private readonly IriConverterInterface $iriConverter, private AnonymousContextBuilderInterface $anonymousContextBuilder)
public function __construct(private readonly NormalizerInterface $decorated, private AnonymousContextBuilderInterface $anonymousContextBuilder)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/AbstractItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ protected function getAttributeValue(object $object, string $attribute, string $
if ($type && $type->getClassName()) {
$childContext = $this->createChildContext($context, $attribute, $format);
unset($childContext['iri'], $childContext['uri_variables']);
$childContext['output']['gen_id'] = $propertyMetadata->getGenId() ?? false;
$childContext['output']['gen_id'] = $propertyMetadata->getGenId() ?? true;

return $this->serializer->normalize($attributeValue, $format, $childContext);
}
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bundle/Resources/config/jsonld.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

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

<!-- Run after serializer.denormalizer.array but before serializer.normalizer.object -->
Expand Down
40 changes: 17 additions & 23 deletions tests/Fixtures/TestBundle/Entity/JsonSchemaContextDummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,37 @@

namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
* JSON Schema Context Dummy.
*
* @ApiResource
*
* @ORM\Entity
*/
#[ORM\Entity]
#[ApiResource]
class JsonSchemaContextDummy
{
/**
* @var int The id
*
* @ApiProperty(identifier=true)
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
#[ApiProperty(identifier: true)]
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
public $id;

/**
* @var array
*
* @ApiProperty(
* attributes={
* "json_schema_context"={
* "type"="array",
* "items"={"type"="string"},
* "minItems"=2,
* "maxItems"=2
* }
* },
* )
*/
#[ApiProperty(
jsonSchemaContext: [
'type' => 'array',
'items' => ['type' => 'string'],
'minItems' => 2,
'maxItems' => 2,
]
)]
private $things = ['pool', 'bag'];

public function getId()
Expand Down
4 changes: 0 additions & 4 deletions tests/JsonLd/Serializer/ObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function testNormalize(): void

$normalizer = new ObjectNormalizer(
$serializerProphecy->reveal(), // @phpstan-ignore-line
$iriConverterProphecy->reveal(),
$contextBuilderProphecy->reveal()
);

Expand Down Expand Up @@ -79,7 +78,6 @@ public function testNormalizeEmptyArray(): void

$normalizer = new ObjectNormalizer(
$serializerProphecy->reveal(), // @phpstan-ignore-line
$iriConverterProphecy->reveal(),
$contextBuilderProphecy->reveal()
);

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

$normalizer = new ObjectNormalizer(
$serializerProphecy->reveal(), // @phpstan-ignore-line
$iriConverterProphecy->reveal(),
$contextBuilderProphecy->reveal()
);

Expand Down Expand Up @@ -133,7 +130,6 @@ public function testNormalizeWithContext(): void

$normalizer = new ObjectNormalizer(
$serializerProphecy->reveal(), // @phpstan-ignore-line
$iriConverterProphecy->reveal(),
$contextBuilderProphecy->reveal()
);

Expand Down

0 comments on commit bb29bab

Please sign in to comment.