openapi-library / OpenAPIValidators

Use Jest or Chai to assert that HTTP responses satisfy an OpenAPI spec
MIT License
189 stars 35 forks source link

`toSatisfyApiSpec` doesn't recognize `:` in path that is not a parameter #286

Open aradbar opened 1 year ago

aradbar commented 1 year ago

Are you using jest or chai? jest

Are you using OpenAPI 2, 3.0.X, or 3.1.0? 3.0.3

Describe the bug clearly When having a path that contains a hard-coded : in it (that does not signify a parameter) toSatisfyApiSpec still treats it as a parameter and ignores the text after the :. that causes a mixup between different paths.

Steps to reproduce the bug:

  1. Have a spec with two paths that are identical except for an ending that container a :. for example POST /api/{prefix}/example:one POST /api/{prefix}/example:two
  2. Test a response to one of them with toSatisfyApiSpec
  3. See error

    
    expected received to satisfy the '200' response defined for endpoint 'POST /api/{prefix}/example:two' in your API spec
    
    received did not satisfy it because: response must have required property 'two'
    
    received contained: { body: { one: 'foo' } }
    
    The '200' response defined for endpoint 'POST /api/{prefix}/example:two' in API spec: {
      '200': {
        description: 'Two',
        content: {
          'application/json': {
            schema: {
              type: 'object',
              required: [ 'two' ],
              properties: { two: { type: 'string' } }
            }
          }
        }
      }
    }

See full example in my branch - https://github.com/aradbar/OpenAPIValidators/blob/bug-report-1/packages/jest-openapi/__test__/colonInUrlBug.test.ts

What did you expect to happen instead? toSatisfyApiSpec to be able to differentiate between the two paths

Are you going to resolve the issue?