【问题标题】:How do I get php-swagger to pick up my HTTP GET method如何让 php-swagger 获取我的 HTTP GET 方法
【发布时间】:2014-10-07 12:28:27
【问题描述】:
<?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操作?? 我认为注释的这种确切语法在几个小时前工作得很好,但我一定改变了一些东西,因为现在它不再工作了...... 有什么想法吗?

【问题讨论】:

    标签: php get annotations swagger


    【解决方案1】:

    嗯,奇怪,现在我删除了 GET 的整个注释,重新编写并重新插入它,它可以工作....

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-06
        • 2019-11-24
        • 1970-01-01
        相关资源
        最近更新 更多