【问题标题】:OpenApi Annotations causing double slashOpenApi Annotations 导致双斜杠
【发布时间】:2021-09-23 20:44:24
【问题描述】:

我正在使用 zircote/swagger-php 根据已添加到现有代码中的 OpenApi 注释生成 API 文档。

在大多数情况下,它运行良好,但我注意到一个奇怪的地方。我有一个方法,indexAction(),它应该返回一个项目列表:

/**
 * @OA\Get(
 *      path="\location",
 *      description="Retrieves a list of locations for the current organisation",
 *      method="indexAction",
 *      @OA\Response(
 *          response="200",
 *          description="List of locations",
 *          @OA\JsonContent(
 *              type="array",
 *              @OA\Items(ref="#/components/schemas/Location")
 *          ),
 *          @OA\XmlContent(
 *              type="array",
 *              @OA\Items(ref="#/components/schemas/Location")
 *          )
 *      )
 * )
 */
public function indexAction()
{

编译文档json文件后,我打开它,这个动作如下:

"paths": {
    "\\location": {
        "get": {
            "summary": "The index action handles index/list requests; it should respond with a\nlist of the requested resources.",
            "description": "Retrieves a list of locations for the current organisation",
            "operationId": "2b36ea7d6a6e350fd6c7564bc908a25b",
            "responses": {
                "200": {
                    "description": "List of locations",
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/components/schemas/Location"
                                }
                            }
                        },
                        "application/xml": {
                            "schema": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/components/schemas/Location"
                                }
                            }
                        }
                    }
                }
            }
        }
    },

由于某种原因,“路径”被列为\\location 而不是我所期望的\location - 有人知道为什么会这样吗?我希望这就够了,如果需要更多代码,我可以提供。

【问题讨论】:

    标签: php swagger openapi openapi-generator swagger-php


    【解决方案1】:

    \\ 只是 JSON 字符串中 \ 字符的转义版本。即"\\location"字符串的实际值为\location

    但是,URL 路径使用/ 正斜杠,OpenAPI 也需要paths start with /。所以你需要更换

    path="\location",
    

    path="/location",
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 2020-12-25
      • 2023-03-16
      相关资源
      最近更新 更多