【问题标题】:testing an array as property of custom class测试一个数组作为自定义类的属性
【发布时间】:2013-12-22 13:02:20
【问题描述】:

如何将数组定义为模型类中的属性?

让我总结一下我做了什么......

我的模型类包含一个数组

 class Author {

        /**
         * @var string {@from body} 
         * name of the Author {@required true}
         */
        public $name = 'Name';

        /**
         * @var string {@type email} {@from body}
         * email id of the Author
         */
        public $email = 'name@domain.com';

        /**
         *  @var array $arr {@type array} array of person
         * {@required true}
         */
        public $arr = array();

    }

我测试 throw restler 的功能是:

/**
     * POST
     * post Author
     *
     * @param {@type Author} $a
     *
     * @return Author
     */
    function postAuthor(Author $a) {
        return $a;
    }

当我尝试远程测试和类函数时抛出 index.html 它作为值返回:

{
    "name":"",
    "email":"",
    "arr":""
}

我需要按如下方式返回:

{
        "name":"",
        "email":"",
        "arr":[]
    }

我该怎么做才能做到这一点?

【问题讨论】:

    标签: php restler swagger


    【解决方案1】:

    我了解到您在谈论 Restler Explorer 将带有 arr 的请求正文显示为字符串而不是数组

    这是因为默认响应被创建为一个简单的帮助器来减少打字,它还不支持复杂的类型

    我们正在我们目前正在开发的新资源管理器中添加 Swagger 1.2 支持

    它将包含一个高级版本的帮助器以正确构建请求正文


    更新以进一步回答

    如果您使用 Restler 3.0 RC5(目前仅在 v3 分支中可用)并如下所示注释您的 api 模型类,您可以让它工作

    /**
     *  @var array $arr {@type Person} array of person
     * {@required true}
     */
    public $arr = array();
    

    【讨论】:

      猜你喜欢
      • 2013-05-25
      • 1970-01-01
      • 2020-03-15
      • 1970-01-01
      • 2012-06-19
      • 1970-01-01
      • 2011-01-14
      • 2015-08-08
      • 1970-01-01
      相关资源
      最近更新 更多