我将swagger-node用于 REST API,我在这里发现了一个荒谬的问题。
这是我的 GET 请求之一:
GET: /students/{id}/{name}
(id 是数字)
现在我写了另一个请求:
GET: /students/routeInfo/{id}
但第二次要求我出现以下错误:
预期类型是数字,找到类型字符串。这显然意味着第二个请求正在尝试“屏蔽”第一个请求。我认为不应该。
我做错了什么还是有其他方法可以解决这个问题?
我将swagger-node用于 REST API,我在这里发现了一个荒谬的问题。
这是我的 GET 请求之一:
GET: /students/{id}/{name}
(id 是数字)
现在我写了另一个请求:
GET: /students/routeInfo/{id}
但第二次要求我出现以下错误:
预期类型是数字,找到类型字符串。这显然意味着第二个请求正在尝试“屏蔽”第一个请求。我认为不应该。
我做错了什么还是有其他方法可以解决这个问题?
OpenAPI 规范 v3.0 文档中描述了完全相同的情况:路径模板匹配部分,第三个示例。它被称为模糊匹配,并且“......由工具决定使用哪个路径。” 该工具当然是 swagger-node。
虽然很奇怪,不是吗!
在您的路径定义中,更改您的“参数”type: number
为type: string
您的路径将如下所示:
/students/routeInfo/{id}:
x-swagger-router-controller: yourStudentController
get:
tags:
- Student
description: description
operationId: yourOperation
parameters:
- name: id
in: path
description: description id of routeInfo
required: true
type: string
在https://swagger.io/docs/specification/paths-and-operations/上查看更多信息