在*Context字符数组中创建一个新的$resourceClass键。
例如,在Symfony 4中,我们可以在config/packages/api_platform.yml文件中添加以下内容:
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']
mercure:
enable_profiler: '%kernel.debug%'
openapi:
title: My API
version: '1.0.0'
patch_formats:
json: ['application/merge-patch+json']
# Add this "resources" configuration
resources:
# This is the key to add
App\Entity\MyEntity:
normalization_context:
groups: ['my_entity_read']
denormalization_context:
groups: ['my_entity_write']
请确保替换实际的“App\Entity\MyEntity”和“my_entity_read”、“my_entity_write”组。