dseax40600 2019-07-23 15:03
浏览 145

Symfony APi平台在api doc中呈现枚举类型

I am using Api platform to create base endpoints and documentation. For this purpose, I use DTO . One of my entity, which converts to DTO, has an enum type which is based on Myclabs/Enum - in doctrine, it mapped like (smallint).

I want, API platform renders this enum, not like the simple scalar value but like nested object with key-value and label - title

For example:

class Choice
{
   /**@var string **/
    $name;
   /**@var int (can be only 1 or only 2) **/
    $measureUnitType;
}

measureUnitType:

class MeasurementUnit extends MyCLabs\Enum\Enum
{
    private const METRIC = 1;
    private const IMPERIAL = 2;
}

So I want the next output:

{
   "name": "testName",
   "require": {
     "value": 1,
     "label": "IMPERIAL"
   }
 }

I have read this piece of doc but honestly, I didn`t realize how achieve my goal

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题