api平台的YAML配置,隐藏字段并使用辅助UUID作为公共ID

时间:2019-12-26 17:47:07

标签: api symfony api-platform.com

我有这个简单的测试实体在工作

App\Entity\Account:
    type: entity
    table: accounts
    attributes:
    id:
        id:
            type: integer
            generator:
                strategy: AUTO
            length: null
            unique: false
            nullable: false
            id: true
    fields:
        uuid:
            type: guid
            scale: 0
            unique: true
            nullable: false
        name:
            type: string
            length: 255
            unique: false
            nullable: false
        currency:
            type: string
            length: 3
            unique: false
            nullable: false

哪个返回此JSON对象

{
    "@context": "/contexts/Account",
    "@id": "/accounts",
    "@type": "hydra:Collection",
    "hydra:member": [
        {
            "@id": "/accounts/1",
            "@type": "Account",
            "uuid": "376ac80f-70b9-4673-8ba0-d1aeb613fd4c",
            "name": "The account 1 name",
            "currency": "EUR",
            "id": 1
        },
        {
            "@id": "/accounts/2",
            "@type": "Account",
            "uuid": "55e878d4-5607-421b-9b90-16ae0d461e8d",
            "name": "Account 2",
            "currency": "USD",
            "id": 2
        }
    ],
    "hydra:totalItems": 2
}

我目前使用id作为数据库关系的内部参考,我需要:

  • uuid设置为公共id,这是通过API请求引用元素的唯一方法
  • 修改IRI以将uuid上的id用作"@id": "/accounts/<UUID>",
  • 隐藏结果中的id(整数),仅供内部使用 我该如何使用yml配置?

0 个答案:

没有答案