pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

Number type matchers when using Pact specification version 2 #958

Open ipetroww opened 4 years ago

ipetroww commented 4 years ago

I am trying to create a contract for a response which contains a number value attribute. Something like the following:

"parent_attr": {  
    "child_attr": 11  
}

The used matchers for this part of the response are the following:

PactDslJsonBody()
    .object("parent_attr")
        .numberType("child_attr", 11)
    .closeObject()

And the result in the pact itself:

"$.parent_attr.child_attr ": {
     "match": "number"
}

The issue comes from the constraint that the consumer and the provider should use pact specification version 2. This results in a pact verification warning about the number attribute:

WARN: Ignoring unsupported matchers [{"match"=>"number"}]

What is the best approach for number type matchers when using pact specification version 2? Is there any way the resulting matcher to be:

"$.body.parent_attr.child_attr ": {
    "match": "type"
}

The same as the one which comes as a result when stringType() is used.

uglyog commented 4 years ago

That's a good point. The number matches are just extensions to type matchers, so we could do that.

ipetroww commented 4 years ago

Hi Ronald,

Thank you for addressing the topic so quickly!