我正在创建一个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
一样,我该如何解决呢?