繁体   English   中英

Restler:复杂对象类型作为参数

[英]Restler: Complex Object Types as Parameters

你好Restler朋友,

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

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

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

示例:

/**
 * 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对象的“复杂类型”(顺便说一下,这对返回的对象非常有用)

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

我错过了什么或者没有实现该功能吗?

在此先感谢帮助我!

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

Restler 3 RC4昨天发布了自定义类参数功能

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

@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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM