SwaggerUI不生成参数的名称属性

时间:2018-06-01 21:57:56

标签: php swagger

我使用这个PHP包为我的PHP REST API创建了swagger.jsonhttps://github.com/zircote/swagger-php

但是,当尝试从Swagger UI测试我的API时,由于某种原因,输入没有名称属性,我收到错误:
Notice: Undefined index: yearNotice: Undefined index: make

这是加载我的swagger.json时生成的HTML:

<tbody>
    <tr class="parameters">
        <td class="col parameters-col_name">
            <div class="parameter__name required">
                <!-- react-text: 360 -->year<!-- /react-text -->
                <span style="color: red;">&nbsp;*</span>
            </div>
            <div class="parameter__type">
                <!-- react-text: 363 -->integer<!-- /react-text -->
                <span class="prop-format">
                    <!-- react-text: 365 -->($<!-- /react-text -->
                    <!-- react-text: 366 -->int32<!-- /react-text -->
                    <!-- react-text: 367 -->)<!-- /react-text -->
                </span>
            </div>
            <div class="parameter__deprecated"></div>
            <div class="parameter__in">
                <!-- react-text: 370 -->(<!-- /react-text -->
                <!-- react-text: 371 -->path<!-- /react-text -->
                <!-- react-text: 372 -->)<!-- /react-text -->
            </div>
        </td>
        <td class="col parameters-col_description">
            <div class="markdown">year to retrieve models for</div>
            <input type="text" class="" title="" placeholder="year - year to retrieve models for" value="">
        </td>
    </tr>
    <tr class="parameters">
        <td class="col parameters-col_name">
            <div class="parameter__name required">
            <!-- react-text: 378 -->make<!-- /react-text -->
            <span style="color: red;">&nbsp;*</span>
            </div>
            <div class="parameter__type">
            <!-- react-text: 381 -->string<!-- /react-text -->
            </div>
            <div class="parameter__deprecated"></div>
            <div class="parameter__in">
            <!-- react-text: 384 -->(<!-- /react-text -->
            <!-- react-text: 385 -->path<!-- /react-text -->
            <!-- react-text: 386 -->)<!-- /react-text -->
            </div>
        </td>
        <td class="col parameters-col_description">
            <div class="markdown">make to retrieve models for</div>
            <input type="text" class="" title="" placeholder="make - make to retrieve models for" value="">
        </td>
    </tr>
</tbody>

以下是我的swagger.json的相应部分:

"/API/GetModels": {
    "get": {
        "summary": "Get Available Models",
        "description": "Gets Models available for passed year/make combination",
        "produces": [
            "application/json"
        ],
        "parameters": [
            {
                "name": "year",
                "in": "path",
                "description": "year to retrieve models for",
                "required": true,
                "type": "integer",
                "format": "int32"
            },
            {
                "name": "make",
                "in": "path",
                "description": "make to retrieve models for",
                "required": true,
                "type": "string"
            }
        ],
        "responses": {
            "200": {
                "description": "successful operation"
            },
            "500": {
                "description": "Internal error"
            }
        }
    }
},

这是我在PHP脚本中的注释:

/**
 *
 * @SWG\Get(path="/API/GetModels",
 *   description="Gets Models available for passed year/make combination",
 *   produces={"application/json"},
 *   summary="Get Available Models", 
 *   @SWG\Parameter(
 *      name="year",
 *      in="path",
 *      type="integer",
 *      format="int32",
 *      description="year to retrieve models for",
 *      required=true,
 *   ),
 *   @SWG\Parameter(
 *      name="make",
 *      in="path",
 *      type="string",
 *      description="make to retrieve models for",
 *      required=true,
 *   ),
 *   @SWG\Response(response=200,description="successful operation"),
 *   @SWG\Response(response=500,description="Internal error")
 *   )
 * )
 */

任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

注释看起来不正确。

由于您使用的是{JID, affiliation, outcast, Reason} -> LBareJID = jid:tolower(jid:remove_resource(JID)), case ?DICT:find(LBareJID, SD#state.subscribers) of {ok, #subscriber{nick = Nick}} -> Nicks = ?DICT:erase(Nick, SD#state.subscriber_nicks), Subscribers = ?DICT:erase(LBareJID, SD#state.subscribers), NewSD = SD#state{subscribers = Subscribers, subscriber_nicks = Nicks}, store_room(NewSD, [{del_subscription, LBareJID}]), send_subscriptions_change_notifications(JID, Nick, unsubscribe, NewSD); _ -> NewSD = SD, ok end, 个参数,因此端点应该看起来像in: path/API/GetModels/{year}/{make} - 也就是说,参数是网址的一部分。

如果参数应该在查询字符串中传递,则它们应该是/API/GetModels/{make}/{year}而不是in: query

要了解有关OpenAPI / Swagger中各种参数类型的更多信息,请参阅Describing Parameters。本指南解释了实际的OpenAPI语法而不是Swagger-PHP注释,但它可以帮助您理解。