Swagger node is taking URL phrase as parameter

1.4k Views Asked by At

I'm using swagger-node for REST APIs and I've found an absurd issue here.

Here's my one of GET requests:

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

(id is number)

And now I wrote another request:

GET: /students/routeInfo/{id}

But the 2nd request me following error:

Expected type is number, found type string. Which clearly means 2nd request is trying to "mask" 1st request. Which I think shouldn't be.

Am I doing something wrong or is there any other way to handle this?

2

There are 2 best solutions below

0
On

The exact same situation is described in the OpenAPI specification v3.0 document: section Path Templating Matching, 3rd example. 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!

1
On

In your path definitions, changeChange your 'parameters' type: number for 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/