节点js swagger将通配符添加到URL

时间:2019-02-19 12:26:09

标签: node.js swagger node-modules swagger-ui

我正在创建一个swagger文档,我想在url中添加通配符,并根据swagger文档中给出的ID来响应请求,

这是我尝试过的

"/products/:id": {
      "x-swagger-router-controller": "ProductsController",
      "get": {
        "description": "Returns Specified Item",
        "operationId": "get_product",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "description": "The Id of the product",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "$ref": "#/definitions/get_product_response"
            }
          },
          "default": {
            "description": "Error",
            "schema": {
              "$ref": "#/definitions/error"
            }
          }
        }
      },
      "patch": {
        "description": "Edit Product Details",
        "operationId": "edit_products",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "type": "string"
          },
          {
            "in": "body",
            "name": "product",
            "schema": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "price": {
                  "type": "string"
                },
                "availability": {
                  "type": "boolean"
                }
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "schema": {
              "$ref": "#/definitions/edited_product"
            }
          },
          "default": {
            "description": "Error",
            "schema": {
              "$ref": "#/definitions/error"
            }
          }
        }
      }
    },

我也尝试添加{id},但是当我尝试使用req.param捕获参数时,我会不断获取:id{id}的硬编码,并在之后添加通配符:id就像/products/:id?id=1一样,我该如何解决呢?

0 个答案:

没有答案