Skip to content

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

@256Taras

Description

@256Taras

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions