4

你好 Restler 朋友们,

我目前正在尝试切换到 Restler 作为我们的主要 Rest-Framework。真正促使我做出决定的是大摇大摆的合规性。我发现为不断增长的系统提供一个很好的自动生成文档非常重要。

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

当然,您可以从“post assoc 数组”中检索所有内容,然后针对对象结构进行验证,但这不会记录在案,客户也不知道他期望什么结构。因此,我将不得不编写一个规范。用手...

例子 :

/**
 * 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 中,而不是作为链接到 Account 对象的“复杂类型”(顺便说一句,这对于返回的对象非常有效)

资源.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}"
    }
    ],

我错过了什么还是没有实现该功能?

提前感谢您帮助我!

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

4

2 回答 2

1

Restler 3 RC4 昨天发布,带有自定义类参数功能

阅读http://restler3.luracast.com/param.html#type以获取示例和测试代码

于 2013-08-16T02:56:28.840 回答
0

@igoru 对于您在评论中的问题,请在函数文档之前使用 PHPDOC

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

**{@from body}**将使请求正文发送的变量。

如果您想从 php 发送它,请使用以下命令:

<?php
$data = array("name" => "Another", "email" => "another@email.com");
$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);
于 2013-06-04T11:29:48.900 回答