Restler: complex object types as parameters

Hello friends Restler,

I'm currently trying to switch to Restler as our main Rest-Framework. What really motivated my decision was respect for swagger. It is very important for me to have good auto-generated documentation for a growing system.

So my problem is that I cannot find a way to use "complex objects" as message parameters, as indicated in swagger here: https://github.com/wordnik/swagger-core/wiki/Parameters .

Of course, you could just extract everything from the post-assembler array and then check for the structure of the objects, but this will not be documented and the client will not know what structures are expected from it. Therefore, I would have to write a specification. by hand ...

Example:

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

It will just be placed as undefined "Object" in resource.json, and not as the "complex type" associated with the Account object (this works fine for returned objects, by the way)

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

Am I missing something or is this function not implemented?

Thanks in advance for your help!

UPDATE: I managed to get serialized objects directly from the mail method nativly, which I, although it was not possible. This does not solve the problem with an automatic document, but is still very valuable.

+4
source share
2 answers

Restler 3 RC4 released yesterday with a class custom parameter function

Read http://restler3.luracast.com/param.html#type for example and testing code

+1
source

@igoru for your question in the comment, use PHPDOC before the function documentation

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

that **{@from body}** will make the variable sent by the request body.

if you want to send it with php use the following:

 <?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); 
0
source

Source: https://habr.com/ru/post/1480077/


All Articles