validator fails for interaction with body as array of numbers

Issue #92 resolved
Vasudev Patel created an issue

For the attached swagger and pact file, the validation fails with the following error:

{
      code: 'request.body.incompatible',
      message: 'Request body is incompatible with the request body schema in the spec file: should pass "formatInt64" keyword validation',
      mockDetails: {
        interactionDescription: 'dummy desc',
        interactionState: '[none]',
        location: '[root].interactions[0].request.body[0]',
        mockFile: 'swaggers/pact.json',
        value: 101
      },
      source: 'spec-mock-validation',
      specDetails: {
        location: '[root].paths./testpath/1.post.parameters[0].schema.items.formatInt64',
        pathMethod: 'post',
        pathName: '/testpath/1',
        specFile: 'swaggers/swagger.json',
        value: undefined
      },
      type: 'error'
    }

It seems like it only happens when request body (most likely it will also happen with response body) is an array of integers.

in lib/swagger-mock-validator/validate-spec-and-mock/validate-json.ts line 48 if I print values of rawJson and dataPath they come out to be [101] and [0] respectively.

Hence in getRawValueFromJson function when we do dataPath.substring(1) it makes the dataPath to be 0] and hence the function returns undefined .

Is the behavior expected? am i missing something in my pact file which might solve this issue?

Comments (5)

  1. Sebastian Tello Account Deactivated

    Hi @Vasudev Patel , thanks for reporting the issue. I was able to reproduce the issue. I’ll try to see what’s going on and come back to you

  2. Sebastian Tello Account Deactivated

    I did a bit of digging and it seems the problem exists only when the array is the root value. I.e.:

    • schema for a value like [101] hits the bug
    • schema for a value like {“value”: [100]} doesn’t.

    I’ll try to get a fix ready sometime this week.

  3. Log in to comment