【问题标题】:Swagger API URL Parameter issueSwagger API URL 参数问题
【发布时间】:2020-07-14 19:32:16
【问题描述】:

我是 swagger API 文档的新手,想部署一个具有查询字符串的 API。这是我在GET方法中传递参数后得到的API。

baseurl/v1/auth/getOTP?mobile=98XXXXXX14

我想要这个:-

baseurl/v1/auth/getOTP/mobile/98XXXXXX14

我正在实施的是:-

"/auth/getOTP": {
  "get": {
    "tags": [
      "pet"
    ],
    "summary": "",
    "description": "",
    "operationId": "findPetsByStatus",
    "produces": [
      "application/json",
      "application/xml"
    ],
    "parameters": [
      {
        "name": "mobile",
        "in": "query",
        "description": "",
        "required": true,
        "type": "string",
      }
    ],
    "responses": {
      "200": {
        "description": "successful operation",
        "schema": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Pet"
          }
        }
      },
      "400": {
        "description": "Invalid value"
      }
    },
    "security": [
      {
        "petstore_auth": [
          "write:pets",
          "read:pets"
        ]
      }
    ]
  }
},

【问题讨论】:

    标签: swagger swagger-ui


    【解决方案1】:

    你的问题在这里:

    {
        "name": "mobile",
        "in": "query", // <-- Right here.
        "description": "",
        "required": true,
        "type": "string",
    }
    

    为了将手机号码放在路径中而不是查询中,您需要更改两件事。

    首先,将路径更改为"/auth/getOTP/mobile/{mobile}"

    二、更改参数说明:

    {
        "name": "mobile",
        "in": "path", // This.
        "description": "",
        "required": true,
        "type": "string",
    }
    

    详细了解 OAS path templates & parameters

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-13
      • 2015-01-25
      • 1970-01-01
      • 2015-02-04
      • 2021-08-03
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多