Skip to content

feat(serializer): global defaults.normalization_context.gen_id configuration option - #7775

Merged
soyuka merged 4 commits into
api-platform:mainfrom
olinox14:feature/global-genid-setting
Feb 19, 2026
Merged

feat(serializer): global defaults.normalization_context.gen_id configuration option#7775
soyuka merged 4 commits into
api-platform:mainfrom
olinox14:feature/global-genid-setting

Conversation

@olinox14

@olinox14olinox14 commented Feb 17, 2026

Copy link
Copy Markdown
Contributor
QA
Branch?main
TicketsNone
LicenseMIT
Doc PRapi-platform/docs#2252

Add the possibility to set a new option in api/config/packages/api_platform.yaml (or config/api-platform.php for Laravel) :

api_platform:
defaults:
normalization_context:
gen_id: false

If set to false, this will globally disable the Skolem IRIs generation for all properties.
If not set, the default value for $context['output']['gen_id'] would stay true.
#[ApiProperty(genId: true|false)] will still take precedence.

@soyuka

Copy link
Copy Markdown
Member

Hi thanks for the feature! Could you add a test (functional or unit your choice)?

I wonder if it would be nice to have actual property defaults.

Allows configuring the `genId` option globally via `defaults.normalization_context`.
Adds new functional tests to verify that `genId` works as expected when configured globally,
and that the `genId` option on `ApiProperty` takes precedence over the global option.
@olinox14

Copy link
Copy Markdown
ContributorAuthor

I added the tests, please note that I only tested it for the use case that pushed me to propose this PR, i.e. a DTO ApiResource with embedded sub-resources (which are not defined as ApiResources). I'm not sure if there are cases where this feature could be needed with the child resources also defined as ApiResources?

Property defaults defined in the configuration file would be even more elegant imo, but I don’t know the project enough to realize the feasibility

@soyuka

Copy link
Copy Markdown
Member

This is perfect thanks!

@soyukasoyuka changed the title Add global defaults.normalization_context.gen_id configuration optionfeat(serializer): global defaults.normalization_context.gen_id configuration optionFeb 19, 2026
@soyuka
soyuka merged commit 383a5fa into api-platform:mainFeb 19, 2026
149 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@olinox14@soyuka