简体   繁体   English

Swagger节点将URL短语作为参数

[英]Swagger node is taking URL phrase as parameter

I'm using swagger-node for REST APIs and I've found an absurd issue here. 我为REST API使用了swagger-node ,在这里发现了一个荒谬的问题。

Here's my one of GET requests: 这是我的GET请求之一:

GET: /students/{id}/{name}

(id is number) (id是数字)

And now I wrote another request: 现在我写了另一个请求:

GET: /students/routeInfo/{id}

But the 2 nd request me following error: 但第2次要求我以下错误:

Expected type is number, found type string . 预期类型为数字,找到类型为string Which clearly means 2 nd request is trying to "mask" 1 st request. 这显然意味着第二请求试图“掩模” 1个请求。 Which I think shouldn't be. 我认为不应该这样。

Am I doing something wrong or is there any other way to handle this? 我是在做错什么,还是有其他方法可以解决这个问题?

In your path definitions, changeChange your 'parameters' type: number for type: string 在路径定义中,更改更改“参数” type: number type: string

Your path will look like this: 您的路径将如下所示:

/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

See more at https://swagger.io/docs/specification/paths-and-operations/ 请参阅https://swagger.io/docs/specification/paths-and-operations/

The exact same situation is described in the OpenAPI specification v3.0 document: section Path Templating Matching, 3rd example. 在OpenAPI规范v3.0文档中描述了完全相同的情况:“路径模板匹配”部分,第3个示例。 It is called ambiguous matching, and "... it's up to the tooling to decide which path to use." 这被称为模糊匹配,并且“ ...由工具决定使用哪个路径。” The tool, of course, being swagger-node. 该工具当然是摇摇欲坠的节点。

It is weird though, isn't it! 不过这很奇怪,不是!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM