Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paths with two parameters return message - 404 Not found #464

Closed
speculees opened this issue Apr 7, 2023 · 1 comment · Fixed by #466
Closed

Paths with two parameters return message - 404 Not found #464

speculees opened this issue Apr 7, 2023 · 1 comment · Fixed by #466
Assignees
Labels
bug Something isn't working

Comments

@speculees
Copy link

Describe the bug
When path has more than one path params - mocks server returns Not found message.
If the /drivers/{driverId} is removed, leaving only one parameter the example is returned.

To Reproduce
Create openapi file with following path /cars/{carId}/drivers/{driverId} with some examples and attempt to access the resource.

Expected behavior
To return selected route variant example

Logs

Displaying logs. Press any key to display main menu again
12:38:14:20 [debug][server] Request received | GET => /api/cars/1/drivers/2 | Assigned id: 062546c7-568a-47f1-a2fe-76fab906a545
12:38:14:20 [debug][server] Sending Not found response | GET => /api/cars/1/drivers/2 | 062546c7-568a-47f1-a2fe-76fab906a545
12:38:14:20 [error][server] Sending Error 'Not Found' | 062546c7-568a-47f1-a2fe-76fab906a545

** Operating system, Node.js an npm versions, or browser version (please complete the following information):**

  • OS: [MacOs, Windows 10]
  • Node.js: [18.15.0]
  • npm: [9.5.0]

Additional context
Pseudo spec:

  /cars/{carId}/drivers/{driverId}:
    get:
      operationId: GetCarDriver
      security: []
      summary: Get driver
      parameters:
        - name: carId
          example: 1 
          in: path
          required: true
          schema:
            type: string
        - name: driverId
          in: path
          required: true
          example: 2
          schema:
            type: string
      responses:
        200:
          description: A
          content:
            application/json:
              ...
              examples:
                one:
                  value:
                    id: 2
                    employmentType: Full-time
                    name: Speculees
                    ...
                    location: Parise, France
                    jobDescription: lorem ipsum
                    responsibilities: lorem ipsum
@javierbrea javierbrea added the bug Something isn't working label Apr 7, 2023
@javierbrea
Copy link
Member

Hi @speculees ,thanks for sharing!

The problem is caused by the regular expression at charge of converting OpenAPI paths into Express paths. After reproducing the issue with your data and enabling the debug log mode, I've seen that a path like the one you described is converted into /cars/:carId}/drivers/{driverId, because the regular expression replaces all the content from the start of the first parameter to the end of the last one as if it was a single parameter.

So, replacing the regular expression /{(\S*)}/gim by /{(\S*?)}/gim in the replaceTemplateInPath method of the plugin fixes the bug.

I'll try to publish a new version with the fix ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants