Skip to content

Validation errors when paths have multiple path parameters #229

@bfreuden

Description

@bfreuden

Which package are you using?
chai-openapi-response-validator

OpenAPI version
3

Describe the bug
When finding the OAPath matching a request path, the validator does not take into account the number of path parameters.
For the moment it only checks the existence of path parameters: OAPaths having no path parameters are favored over templated OAPaths (paths with path parameters).

To Reproduce

Create an API like this:

POST /shops/{shop}/pets/_search
GET /shops/{shop}/pets/{pet}

Depending on the declaration order of paths in the spec, a request like POST /shops/12345/pets/_search, might unexpectedly raise a validation error like this:
Request operations found for path '/shops/{shop}/pets/{pet}' in API spec: POST
Indeed: there is only a GET here.
That's because the current strategy based on the existence of path parameters does not work here since both paths are templated paths.

Expected behavior
I expect the library to realize that /shops/{shop}/pets/_search was called and not to throw any validation error.

Are you going to resolve the issue?
Yes: I have already written 2 tests (one for chai-openapi-response-validator and one for jest-openapi) based on the preferNonTemplatedPathOverTemplatedPath.test.ts tests and I have corrected the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    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