Hi, one question, I have an openAPI 3.0.3 spec wit...
# pact-jvm
p
Hi, one question, I have an openAPI 3.0.3 spec with "oneOf" for body responses, when I match the pact agains swagger-mock-validator, I get the error "response.body.incompatible: 1". exists any matcher that allows to match with one of the responses?
t
We'll need more information to be able to help with this. What is in your pact? What is in your spec?
Pact doesn't support "or", because that's not how it works - for more information see https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes
but, if your pact matches one of the oneOf types, it should still pass. So I think something else is going on.
p
yes, it should match, but i got this even with a simple example. This is my pact.json
Copy code
{
  "consumer": {
    "name": "consumer-sync"
  },
  "interactions": [
    {
      "description": "Read item",
      "request": {
        "matchingRules": {
          "path": {
            "combine": "AND",
            "matchers": [
              {
                "match": "regex",
                "regex": "/read/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
              }
            ]
          }
        },
        "method": "GET",
        "path": "/read/2b4665bb-8cf0-dc20-1d1c-fc143c17eb84"
      },
      "response": {
        "body": {
          "id": "e2490de5-5bd3-43d5-b7c4-526e33f71304",
          "number": 100
        },
        "generators": {
          "body": {
            "$.id": {
              "type": "Uuid"
            },
            "$.number": {
              "max": 2147483647,
              "min": 0,
              "type": "RandomInt"
            }
          }
        },
        "headers": {
          "Content-Type": "application/json"
        },
        "matchingRules": {
          "body": {
            "$.id": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "regex",
                  "regex": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
                }
              ]
            },
            "$.number": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "number"
                }
              ]
            }
          }
        },
        "status": 200
      }
    }
  ],
  "metadata": {
    "pact-jvm": {
      "version": "4.3.9"
    },
    "pactSpecification": {
      "version": "3.0.0"
    }
  },
  "provider": {
    "name": "provider-sync"
  }
}
And this is my openApi spec
Copy code
openapi: 3.0.3
info:
  title: example-api
  description: |
    Example Public API.
  version: 0.3.0-SNAPSHOT
  license:
    name: mylicense
    url: <https://mydomain.com/license>
servers:
  - url: <https://mydomain.com/service>

paths:
  /read/{uuid}:
    get:
      summary: "Read one item"
      operationId: "read"
      parameters:
      - in: path
        name: uuid
        schema:
          type: string
          format: uuid
        required: true
        description: UUIDv4 of the item
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: "object"
                oneOf:
                  - $ref: "#/components/schemas/read"
                  - $ref: "#/components/schemas/readDetail"
        "404":
          description: "Item Not Found"
        "403":
          description: "Forbiden Access"
        "401":
          $ref: "#/components/responses/UnauthorizedError"
  
components:
  responses:
    UnauthorizedError:
      description: Access token is missing or invalid
    BadRequestError:
      description: Request parameters invalid
  schemas:
    read:
      required:
        - id
      properties:
        id:
          type: string
          format: uuid
    readDetail:
      required:
        - id
      properties:
        id:
          type: string
          format: uuid
        number:
          type: integer
          format: int32
And this is my swagger-mock-validator response:
Copy code
Mock file "pacts/consumer-sync-provider-sync.json" is not compatible with spec file "openapitest.yml"
1 error(s)
        response.body.incompatible: 1
0 warning(s)
{
  warnings: [],
  errors: [
    {
      code: 'response.body.incompatible',
      message: 'Response body is incompatible with the response body schema in the spec file: should match exactly one schema in oneOf',
      mockDetails: {
        interactionDescription: 'Read item',
        interactionState: '[none]',
        location: '[root].interactions[0].response.body',
        mockFile: 'pacts/consumer-sync-provider-sync.json',
        value: { id: 'e2490de5-5bd3-43d5-b7c4-526e33f71304', number: 100 }
      },
      source: 'spec-mock-validation',
      specDetails: {
        location: '[root].paths./read/{uuid}.get.responses.200.content.application/json.schema.oneOf',
        pathMethod: 'get',
        pathName: '/read/{uuid}',
        specFile: 'openapitest.yml',
        value: [
          {
            required: [ 'id' ],
            properties: { id: { type: 'string', format: 'uuid' } }
          },
          {
            required: [ 'id' ],
            properties: {
              id: { type: 'string', format: 'uuid' },
              number: { type: 'integer', format: 'int32' }
            }
          }
        ]
      },
      type: 'error'
    }
  ]
}

Error: Mock file "pacts/consumer-sync-provider-sync.json" is not compatible with spec file "openapitest.yml"
it's extrange. I don't know what it happens. What is wrong?
t
My guess is that
format: uuid
is not the same in the validator as in your pact - it's challenging because the openapi spec doesn't define uuid.
I agree that your pact matches that spec, so this is a problem with the validator I reckon. I would contact them on their issue tracker.
p
I have tried also to remove the uuid and use a number and a string, and happens the same. But if I remove one of the refs in the "oneof" response, the pact passes and it's verified.
So I think the problem is with the oneOf
maybe the problem is with swagger-mock-validator
t
definitely
p
thanks Timothy
one more question why exists two different swagger-mock-validator one in bitbucket and another in github from pactflow?
t
No idea, ask in #CLS16AVEE
p
thanks!