如何让php-swagger选择我的HTTP GET方法

时间:2014-10-07 12:28:28

标签: php get annotations swagger

<?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}
 *      ------------------------------------------------------------------------
 *
 *      @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}
 *      ------------------------------------------------------------------------
 *
 *      @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;

但是,swagger-php会返回此JSON响应:

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

}

注意它忽略了GET方法的HTTP操作? 我认为注释的这种确切语法在几个小时前就可以正常工作了,但我必须改变一些东西,因为现在它已经不再适用了.... 有什么想法吗?

2 个答案:

答案 0 :(得分:0)

嗯很奇怪,现在我删除了GET的整个注释,重新编写并重新插入它并且它有效....

答案 1 :(得分:0)

现在我找到了忽略我的GET方法的原因。 事实证明,即使注释结构100%正确,php-swagger也会忽略任何包含TABS的文档块。 希望这有助于其他人

相关问题