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

[BUG] OpenAPI route validation fails on trailing slashes in express-oas-validator #31

Open
256Taras opened this issue Nov 2, 2023 · 0 comments

Comments

@256Taras
Copy link

256Taras commented Nov 2, 2023

Description

When using express-oas-validator with express.js, the routes that end with a trailing slash are not being validated correctly against the OpenAPI definitions. This leads to the validator not recognizing valid endpoints if they are defined without a trailing slash in the OpenAPI documentation but are called with one (e.g., calling /api/forbidden-words/ when the OpenAPI defines /api/forbidden-words).

Steps to Reproduce

  1. Define a route in Express without a trailing slash (e.g., /api/forbidden-words).
  2. Set up the express-oas-validator middleware with OpenAPI definitions matching the route.
  3. Call the endpoint with a trailing slash (e.g., /api/forbidden-words/).
  4. The validator responds with an error stating that the method is not found in the OpenAPI definition.

Expected Behavior

The validator should either recognize that /api/forbidden-words/ and /api/forbidden-words are the same endpoint, or there should be an option to normalize the URL before validation to ensure consistency.

Actual Behavior

The validator returns an error: Method: "get" not found in the OpenAPI definition for "/api/forbidden-words/" endpoint.

Possible Solution

As a temporary workaround, routes can be normalized by stripping trailing slashes before validation. However, it would be preferable to have this handled within the library either by default or via a configuration option.

Additional Context

Please let me know if there are any more details I can provide or if a fix or workaround is already available. Thank you for your assistance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant