Gabriel Vasconcelos
03/18/2025, 5:09 PM{
"openapi": "3.0.1",
"info": {
"title": "IDEServices",
"description": "IDEServices REST API",
"version": "v1"
},
"paths": {
"/asset-model/v1/features": {
"get": {
"summary": "Gets the stored Feature Toggles.",
"description": "Gets the stored Feature Toggles.",
"operationId": "GetAllFeatureTogglesValues",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"required": [
"key"
],
"type": "object",
"properties": {
"key": {
"minLength": 10,
"type": "string"
}
},
"additionalProperties": false
}
}
}
}
}
}
}
}
}
}
and this sample pact:
{
"consumer": {
"name": "web_ide"
},
"interactions": [
{
"description": "Get all features",
"pending": false,
"request": {
"method": "GET",
"path": "/asset-model/v1/features"
},
"response": {
"body": {
"content": [
{
"key": "bigexample"
}
],
"contentType": "application/json",
"encoded": false
},
"headers": {
"Content-Type": [
"application/json"
]
},
"matchingRules": {
"body": {
"$[*].key": {
"combine": "AND",
"matchers": [
{
"match": "what I put here doesnt seem to matter"
}
]
}
},
"header": {},
"status": {}
},
"status": 200
},
"type": "Synchronous/HTTP"
}
],
"metadata": {
"pact-js": {
"version": "14.0.0"
},
"pactRust": {
"ffi": "0.4.22",
"models": "1.2.3"
},
"pactSpecification": {
"version": "4.0"
}
},
"provider": {
"name": "IDE-Services"
}
}
I get no errors no matter how I change the matchingRules. but if I change the example to something else, I get
location: '[root].paths./asset-model/v1/features.get.responses.200.content.application/json.schema.items.properties.key.minLength'
are we doing something wrong? aren't the matchingRules suppose to be more important than the example in the request/response?Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
• Matchers are currently ignored by the cross-contract validation process but may be supported at a later date
Gabriel Vasconcelos
03/18/2025, 5:21 PMYousaf Nabi (pactflow.io)
Gabriel Vasconcelos
03/18/2025, 6:19 PMYousaf Nabi (pactflow.io)
I was under the assumption that the rules of the pact had to match the rules of the swagger, not that the example of the pact had to match those rulesdid you see that in the documentation anywhere? ie the following block in an openapi
bank_account_currency:
maxLength: 3
minLength: 3
pattern: '^[A-Z]{3,3}$'
type: string
description: ''
the consumer is bound by the pattern in the openapi, if they need something different then they would need to discuss that with their provider.
you can use matchers in your tests on the consumer side to make them more flexible for matching there, but as our documentation states, they will be ignored on the provider verification side.
if you need verification with matchers, just switch to using full pact verificationGabriel Vasconcelos
03/18/2025, 6:25 PMyou can use matchers in your tests on the consumer side to make them more flexible for matching there, but as our documentation states, they will be ignored on the provider verification side.so this means that the consumer validation takes it in consideration? isn't it always a validation via
swagger-mock-validator? so they would be ignored regardless, right?Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Gabriel Vasconcelos
03/18/2025, 6:27 PMGabriel Vasconcelos
03/18/2025, 6:27 PMMatt (pactflow.io / pact-js / pact-go)
so bidirectional only validates types? and can’t even do regex?For clarity. it validates against the schema in the OpenAPI document
Matt (pactflow.io / pact-js / pact-go)
swagger-mock-validator? so they would be ignored regardless, right?
it would only validate the request portion, as the provider portion isn’t tested until later (in Pact testing)Matt (pactflow.io / pact-js / pact-go)
Gabriel Vasconcelos
03/19/2025, 9:37 AMFor clarity. it validates against the schema in the OpenAPI document@Matt (pactflow.io / pact-js / pact-go) it is possible to have matchingRules in the request too, correct? we've been investing in bidirectional since we already generate our openAPIs for backstage so it had good synergy, but this is kind of a problem. our fear is that it creates a gap: 1. Consumer has pact with an example in it's body and some regex matchingRules 2. That example matches the regex from the provider swagger a. the test will pass, as expected 3. The provider changes their regex into something that still matches that example but breaks the consumer matching rules a. the test will pass when it breaks the consumer matchingRules is this a correct assumption?
Matt (pactflow.io / pact-js / pact-go)
it is possible to have matchingRules in the request too, correct?yes, but they are only evaluated at contract generation time - they aren’t checked to match the OAS
Matt (pactflow.io / pact-js / pact-go)
we’ve been investing in bidirectional since we already generate our openAPIs for backstage so it had good synergy, but this is kind of a problem. our fear is that it creates a gap:
1. Consumer has pact with an example in it’s body and some regex matchingRules
2. That example matches the regex from the provider swagger
a. the test will pass, as expected
3. The provider changes their regex into something that still matches that example but breaks the consumer matching rules
a. the test will pass when it breaks the consumer matchingRules
is this a correct assumption?Yes, it is. But Pact isn’t guaranteed to pick this up either. If the provider can return multiple values that matches its own “rules”, it’s still plausible it always returns a value that matches the consumer’s (i.e. Pact can’t exhaustively check all possible responses).
Gabriel Vasconcelos
03/19/2025, 5:23 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Gabriel Vasconcelos
03/20/2025, 9:38 AMMatt (pactflow.io / pact-js / pact-go)
making bidirectional strictly superior to consumer-drivenI don’t think it would ever be superior to consumer-driven with Pact, because Pact actually replays the requests against the running provider - whereas BDCT only checks the schema. But I agree it would be stronger
Gabriel Vasconcelos
03/20/2025, 4:46 PMYousaf Nabi (pactflow.io)