Pablo Cabo
09/06/2022, 12:38 PMTimothy Jones
09/07/2022, 3:07 AMTimothy Jones
09/07/2022, 3:08 AMTimothy Jones
09/07/2022, 3:09 AMPablo Cabo
09/07/2022, 6:14 AM{
"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
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:
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"
Pablo Cabo
09/07/2022, 6:38 AMTimothy Jones
09/07/2022, 7:15 AMformat: uuid
is not the same in the validator as in your pact - it's challenging because the openapi spec doesn't define uuid.Timothy Jones
09/07/2022, 7:15 AMPablo Cabo
09/07/2022, 7:19 AMPablo Cabo
09/07/2022, 7:19 AMPablo Cabo
09/07/2022, 7:30 AMTimothy Jones
09/07/2022, 8:06 AMTimothy Jones
09/07/2022, 8:07 AMPablo Cabo
09/07/2022, 8:10 AMPablo Cabo
09/07/2022, 8:12 AMPablo Cabo
09/07/2022, 8:13 AMTimothy Jones
09/07/2022, 8:13 AMPablo Cabo
09/07/2022, 8:13 AM