2013-05-10 77 views
4

您好Restler朋友,Restler:作为参数的复杂对象类型

我目前正在尝试切换到Restler作为我们的主休息框架。我的决定真正激发了我的决定,就是招摇顺应。我发现为一个长大的系统提供一个很好的自动生成文档非常重要。

所以,我的问题是,我似乎无法找到一种方法来使用“复杂的对象”作为在swagger中指定的后置参数:https://github.com/wordnik/swagger-core/wiki/Parameters

当然你可以从“后关联数组”中检索所有内容,然后根据对象结构进行验证,但这不会被记录下来,客户端也不会知道他期望的结构。因此我必须写一个规范。用手...

例子:

/** 
* Create a new Account, based on the structure of the Account Object 
* 
* @param Account $account {@from body} 
* 
* @return string 
* 
*/ 
protected function post(Account $account){...} 

这会简单地把作为resource.json未定义的“对象”,而不是作为一个“复合型”链接到帐户对象(这是完美工作的方式返回的对象)

Resource.json

"parameters": [ 
    { 
    "name": "REQUEST_BODY", 
    "description": "Paste JSON data here with the following property.<hr/><mark>account</mark> <i>(required)</i>: add <mark>@param {type} $account {comment}</mark> to describe here", 
    "paramType": "body", 
    "required": true, 
    "allowMultiple": false, 
    "dataType": "Object", 
    "defaultValue": "{\n \"account\": \"\"\n}" 
    } 
    ], 

我错过了什么或者是有没有实现?

在此先感谢您的帮助!

UPDATE:我设法直接从序列化对象中直接取出post方法,这虽然是不可能的。这并不能解决自动文档问题,但仍然非常有价值。

+1

V3分支(Restler 3.0 RC4)在这方面有一些进展,但Resources类仍然不扩展或解析参数类。我们将很快添加该功能 – Luracast 2013-05-10 14:16:44

+0

感谢您的回复。当我有空时,我会看看分支。 – Gingonic 2013-05-10 14:58:13

+0

附加问题:客户端应该如何在请求体中发送参数?我试图传递一个简单的JSON对象,但它不起作用。 – igorsantos07 2013-05-22 19:20:29

回答

0

@igoru 在评论 使用PHPDoc的你的问题函数文档

* @param {type} $variable {comment} **{@from body}** 

**{@from body}**将使通过请求体发送的变量之前。

,如果你想从PHP发送,使用以下命令:

<?php 
$data = array("name" => "Another", "email" => "[email protected]"); 
$data_string = json_encode($data); 

$ch = curl_init("http://restler3.luracast.com/examples/_007_crud/index.php/authors"); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     'Content-Type: application/json', 
     'Content-Length: ' . strlen($data_string)) 
); 

$result = curl_exec($ch); 
echo($result); 
相关问题