Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SwaggerUI未为参数生成名称属性_Php_Swagger - Fatal编程技术网

Php SwaggerUI未为参数生成名称属性

Php SwaggerUI未为参数生成名称属性,php,swagger,Php,Swagger,我使用以下PHP包为我的PHP REST API创建了我的swagger.json: 但是,当尝试从Swagger UI测试我的API时,由于某种原因,输入没有name属性,我得到一个错误: 通知:未定义索引:年份和通知:未定义索引:make 这是加载my swagger.json时生成的HTML: <tbody> <tr class="parameters"> <td class="col parameters-col_name">

我使用以下PHP包为我的PHP REST API创建了我的
swagger.json

但是,当尝试从Swagger UI测试我的API时,由于某种原因,输入没有name属性,我得到一个错误:
通知:未定义索引:年份
通知:未定义索引:make

这是加载my 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>
以下是我在PHP脚本中的注释:

"/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"
            }
        }
    }
},
/**
 *
 * @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")
 *   )
 * )
 */

有什么办法可以解决这个问题吗?

注释看起来不对

由于您在:path
参数中使用了
,因此端点应该类似于
/API/GetModels/{year}/{make}
/API/GetModels/{make}/{year}
——也就是说,这些参数是URL的一部分

如果参数应该在查询字符串中传递,那么它们应该是
in:query
而不是
in:path


要了解有关OpenAPI/Swagger中各种参数类型的更多信息,请参阅。本指南解释了实际的OpenAPI语法,而不是招摇过市的PHP注释,但它应该可以帮助您了解这些错误。

您在哪里看到这些错误?你能发布一个截图吗?它们不应该以任何方式影响“试用”功能(例如,也有没有名称的输入,“试用”工作正常。)此外,注释也不太正确。由于您使用的是路径参数,端点应该类似于
/API/GetModels/{year}/{make}
/API/GetModels/{make}/{year}
。或者,如果参数应该在查询字符串中传递,那么它们应该是
in:query
而不是
in:path
。我不知道
in
属性中
query
值。@Helen,请将您的评论作为答案发表。