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
8 changes: 8 additions & 0 deletions core/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ api_platform:
normalization_context:
# Default value to omit null values in conformance with the JSON Merge Patch RFC.
skip_null_values: true

# Set to false to disable the generation of Skolem IRIs (`/.well-known/genid/{id}`) globally.
# Available since API Platform 4.3, see the serialization documentation.
gen_id: true
denormalization_context: ~
swagger_context: ~
openapi_context: ~
Expand Down Expand Up @@ -756,6 +760,10 @@ return [
'normalization_context' => [
// Default value to omit null values in conformance with the JSON Merge Patch RFC.
'skip_null_values' => true,

// Set to false to disable the generation of Skolem IRIs (`/.well-known/genid/{id}`) globally.
// Available since API Platform 4.3, see the serialization documentation.
'gen_id' => true,
],

'denormalization_context' => null,
Expand Down
51 changes: 51 additions & 0 deletions core/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,57 @@ class PlainIdentifierDenormalizer implements DenormalizerInterface, Denormalizer
}
```

## Disabling Skolem IRIs for Embedded Objects

When a relation is embedded and the related object has no identifier, API Platform generates a
Skolem IRI (`/.well-known/genid/{id}`) as the `@id` of the embedded object. To omit it, set the
`genId` option of `#[ApiProperty]` to `false` on the property:

```php
<?php
// api/src/ApiResource/Book.php
namespace App\ApiResource;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;

#[ApiResource]
class Book
{
#[ApiProperty(genId: false)]
public ?Author $author = null;
}
```

Since API Platform 4.3, you can change the default for every property with the `gen_id` key of the
global `normalization_context` default. It is `true` when not set:

```yaml
# api/config/packages/api_platform.yaml
api_platform:
defaults:
normalization_context:
gen_id: false
```

For Laravel, use the same key in `config/api-platform.php`:

```php
<?php
// config/api-platform.php

return [
'defaults' => [
'normalization_context' => [
'gen_id' => false,
],
],
];
```

The `genId` option of `#[ApiProperty]` takes precedence over the global default, so
`#[ApiProperty(genId: true)]` keeps generating the Skolem IRI of a given property.

## Property Normalization Context for Symfony

If you want to change the (de)normalization context of a property, for instance if you want to
Expand Down
Loading