Skip to content

Conversation

@Qanah
Copy link

@Qanah Qanah commented Sep 18, 2018

pass queryParameters array from the docblock

pass queryParameters array from the docblock
@Qanah
Copy link
Author

Qanah commented Sep 18, 2018

Using for @queryParameters
the title and body is required to pass demo values you need to add @queryParameters to docblock as JSON

My TestRequest

class TestRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title' => 'required|max:255',
            'body' => 'required',
            'type' => 'in:foo,bar',
            'thumbnail' => 'required_if:type,foo|image',
        ];
    }
}

My Test API

    /**
     *
     * This is the short description [and should be unique as anchor tags link to this in navigation menu]
     *
     * This can be an optional longer description of your API call, used within the documentation.
     *
     * @queryParameters {
     *  "title": "my test title value",
     *  "body": "my test body value"
     * }
     *
     * @param TestRequest $request
     * @return array
     */
    public function test(TestRequest $request) {

        return [
            'uuid' => uniqid(),
            'user' => [
                'name' => 'ibraheem',
                'email' => 'i.qanah@gmail.com'
            ],
            'data' => $request->all()
        ];
    }

Result

{
    "uuid": "5ba0b2d47f6bf",
    "user": {
        "name": "ibraheem",
        "email": "i.qanah@gmail.com"
    },
    "data": {
        "title": "my test title value",
        "body": "my test body value"
    }
}

*/
protected function getQueryParameters($tags)
{
$responseTags = array_filter($tags, function ($tag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean $queryParamTags, not $responseTags :)

@shalvah
Copy link
Contributor

shalvah commented Sep 22, 2018

Hey @Qanah thank you for this. I have a few thoughts:

  • I suggest we go with something like this instead:
    /**
     *
     * @queryParam title Description of this param
     * @queryParam per_page Description of this one
     * 
     */

Reason is, I feel using a JSON object is a bit odd, since query parameters don't get passed as JSON, and are individual entities, not one JSON object. Also, this is clearer and more similar to the usual PHPDoc tags

  • Also, you'd need to modify the markdown source files to include a section for query parameters.

  • Can you add tests? A screenshot of how this looks in the generated documentation would also be nice.

@shalvah shalvah closed this Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants