Я использую Symfony 4.3 и API Platform 2.4. В моем API есть ресурсы 'groups' и связанные с ними подресурсы 'phones':
{
"@context": "/contexts/groups",
"@id": "/groups/7116",
"@type": "groups",
"id": 7116,
"name": "Standard Test",
"description": "",
"phones": {
"7848412": {
"@id": "/phones/7848412",
"@type": "phones",
"id": 7848412,
"phone": "+412344545656",
"a": "o2",
"b": "",
"c": "",
"d": "",
"e": ""
}
}
Ресурсы YAML:
entities\ClientPhoneGroup:
shortName: 'groups'
description: "Phone's group"
collectionOperations:
post:
denormalization_context:
groups: ['write']
itemOperations:
get: ~
put:
denormalization_context:
groups: ['write']
delete: ~
attributes:
normalization_context:
groups: ['read']
security: "is_granted('IS_AUTHENTICATED_FULLY')"
subresource_operations:
phone_get_subresource:
method: 'GET'
properties:
id:
identifier: true
phones:
subresource:
resourceClass: 'entities\ClientPhone'
collection: false
и
entities\ClientPhone:
shortName: 'phones'
description: "Phones list by group"
collectionOperations:
post:
path: /groups/{group_id}/phones
requirements:
group_id: '\d+'
denormalization_context:
groups: ['write']
itemOperations:
get: ~
put:
denormalization_context:
groups: ['write']
delete: ~
attributes:
normalization_context:
groups: ['read']
security: "is_granted('IS_AUTHENTICATED_FULLY') "
сериализаторыYAML:
entities\ClientPhoneGroup:
attributes:
id:
groups: ['read']
name:
groups: ['read', 'write']
description:
groups: ['read', 'write']
phones:
groups: ['read']
и
entities\ClientPhone:
attributes:
id:
groups: ['read']
phone:
groups: ['read', 'write', 'edit']
a:
groups: ['read', 'write', 'edit']
b:
groups: ['read', 'write', 'edit']
c:
groups: ['read', 'write', 'edit']
d:
groups: ['read', 'write', 'edit']
e:
groups: ['read', 'write', 'edit']
- Как изменить список встроенных телефонов на '/ groups / 7116 / phones' в ресурсе groups?
- Как добавить ссылку на ресурс 'group' (например, / groups / 7116) на подресурс телефона?