swagger-mock-validator does not work when the OASv3 has a pattern on the path param
Issue #88
new
When my API in open-api-v3 has a pattern on the path parameters, swagger-mock-validator fails to validate with a weird error. Example shown below. Can you verify if this is a known bug in the tool.
pact.json
{
"consumer": {
"name": "helloworld-sdk"
},
"provider": {
"name": "helloworld"
},
"interactions": [
{
"description": "a request to perform a healthcheck",
"providerState": "performs healthcheck",
"request": {
"method": "GET",
"path": "/helloworld/v1/healthcheck/41eeea9b-d51f-4425-9b7a-272a6c9778a0",
"matchingRules": {
"$.path": {
"match": "regex",
"regex": "\\/helloworld\\/v1\\/healthcheck\\/[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}"
}
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"body": {
"version": "0.1.0"
},
"matchingRules": {
"$.body": {
"match": "type"
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
open-api-v3.json
{
"openapi": "3.0.0",
"info": {
"title": "helloworld",
"version": "v1",
"description": "API Specifications for helloworld, apiVersion: v1",
"contact": {
"email": "abc@def.com"
},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"paths": {
"/helloworld/v1/healthcheck/{logicalId}": {
"get": {
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/healthcheckSchema"
}
}
}
}
},
"operationId": "healthcheck",
"description": "API to perform service healthcheck",
"parameters": [
{
"required": true,
"name": "logicalId",
"in": "path",
"schema": {
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/"
}
}
]
}
}
},
"components": {
"schemas": {
"healthcheckSchema": {
"type": "object",
"properties": {
"version": {
"type": "string"
}
},
"required": [
"version"
],
"additionalProperties": false,
"title": "healthcheckSchema"
}
}
}
}
Results in the following error:
$ /node_modules/.bin/swagger-mock-validator ./open-api-v3.json pact.json
Mock file "pact.json" is not compatible with spec file "./open-api-v3.json"
1 error(s)
request.path-or-method.unknown: 1
0 warning(s)
{
warnings: [],
errors: [
{
code: 'request.path-or-method.unknown',
message: 'Path or method not defined in spec file: GET /helloworld/v1/healthcheck/41eeea9b-d51f-4425-9b7a-272a6c9778a0',
mockDetails: {
interactionDescription: 'a request to perform a healthcheck',
interactionState: 'performs healthcheck',
location: '[root].interactions[0].request.path',
mockFile: 'pact.json',
value: '/helloworld/v1/healthcheck/41eeea9b-d51f-4425-9b7a-272a6c9778a0'
},
source: 'spec-mock-validation',
specDetails: {
location: '[root].paths',
pathMethod: null,
pathName: null,
specFile: './open-api-v3.json',
value: { '/helloworld/v1/healthcheck/{logicalId}': [Object] }
},
type: 'error'
}
]
}
Error: Mock file "pact.json" is not compatible with spec file "./open-api-v3.json"
at ./node_modules/swagger-mock-validator/dist/cli.js:85:36
at Generator.next (<anonymous>)
at fulfilled (./node_modules/swagger-mock-validator/dist/cli.js:6:58)
This looks like it may have been an issue with the regexs used rather than an issue with this tool. I was able to successfully get 0 errors 0 warnings with these files once I updated the regexs in the pact and swagger files.
Pact regex - remove one of each of the double back slashes in the path:
Swagger regex - remove the trailing slash at the end:
I think this issue can probably be closed as a non-issue, as it appears this tool already supports this functionality.