How do I get php-swagger to pick up my HTTP GET method

710
<?php
/**
 * @SWG\Resource(
 *      basePath="http://dizplayzone.com/api",
 *      resourcePath="/account",
 *      description="Read information on a company dashboard",
 *      swaggerVersion="1.2",
 *      apiVersion="1.1",
 * )
 */

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;

$account = $app['controllers_factory'];

/**
 *      /account/{id}
 *

However, swagger-php returns this JSON response:

{-code-2}

}

Note that it ignores the GET method HTTP operation ?? I think this exact syntax for the annotations worked fine a couple of hours ago, but I must have changed something because now it no longer works.... Any ideas ?

394

Answer

-- * * @SWG\Api( * path="/account/{id}", * @SWG\Operation( * method="GET", * summary="Returns info from a company dashboard", * notes="Returns info from a company dashboard", * type="account", * nickname="view_account", * @SWG\Parameter( * name="id", * description="Company ID", * required=true, * type="integer", * paramType="path" * ), * @SWG\ResponseMessage(code=404, message="Bad, really bad name.") * ), * ) * * * @trans foo,bar * */ $account->get('/account/{id}', function ($id) use ($app) { ... return "Welcome {$user['username']}!"; }); /** * /account/{id} *
709

Answer

-- * * @SWG\Api( * path="/account/{id}", * @SWG\Operation( * method="POST", * summary="Add info to a company dashboard", * notes="Add info to a company dashboard", * type="account", * nickname="post_to_account", * @SWG\Parameter( * name="id", * description="Company ID", * required=true, * type="integer", * paramType="path" * ), * @SWG\ResponseMessage(code=404, message="Bad, really bad name.") * ) * ) * * */ $account->post('/account/{id}', function ($id) use ($app) { .... }); return $account;|||{ "basePath":"http://dizplayzone.com/api", "swaggerVersion":"1.2", "apiVersion":"1.1", "resourcePath":"/account", "apis":[ { "path":"/account/{id}", "operations":[ { "method":"POST", "summary":"Add info to a company dashboard", "nickname":"post_to_account", "type":"account", "parameters":[ { "paramType":"path", "name":"id", "type":"integer", "required":true, "description":"Company ID" } ], "responseMessages":[ { "code":404, "message":"Bad, really bad name." } ], "notes":"Add info to a company dashboard" } ] } ]
639

Answer

Solution:

Hmm strange, now I removed the entire annotation for GET, re-wrote it and re-inserted it and it it works....

831

Answer

Solution:

Now I found the reason why my GET method was ignored. It turns out that php-swagger will ignore any docblock that contains TABS even if the annotation structure is 100% correct. Hope this helps others

People are also looking for solutions to the problem: php - Get property call from parent class

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.