Hi Pactflow team, wanted to ask if there was a rel...
# pactflow
t
Hi Pactflow team, wanted to ask if there was a release of some new version of Pactflow yesterday or today? We are on Pactflow Version
a48afdec7
currnently, and bi-directional contract verification started failing suddenly without any obvious reason on our side (or I haven’t found it yet). So, I wanted to double-check if this is on Pactflow side. Thanks!
m
Yes, we did make a minor change to enforce
additionalProperties
set to
false
If you were having passing tests before, it’s likely you were getting false positives
What error are you getting?
t
What error are you getting?
Response body is incompatible with the response body schema in the spec file: should NOT have additional properties
looks like it’s related to the changes.
If you were having passing tests before, it’s likely you were getting false positives
interesting, thank you!
m
yep, that’s exactly the problem
basically, if you had it set to
true
(or omitted) it meant that the consumer could ask for any fields in the response, and it would always pass
now, it’s (possibly) correctly telling you that’s not the case
if you can share the request body (consumer) and provider OAS (or just the schema for the request that’s failing) we can tell you. If you’re unable to share here and can’t get to the bottom of it, please raise a ticket at support@pactflow.io and we can look into it privately for you
👌 1
y
Hey @Tatiana Shepeleva, for a bit of detail on the change, and background thread for reading, please checkout the release notes https://github.com/pactflow/swagger-mock-validator/releases/tag/11.0.0 This point is relevant in your case, with the previous behaviour.
Test incorrectly passes when mock expects a field that is not in the spec
https://bitbucket.org/atlassian/swagger-mock-validator/issues/84/test-incorrectly-passes-when-mock-expects Will look to the get the documentation on the Pactflow docs site updated asap, and I could probably add some additional error messaging back to the user, if it's relevant. (Would a link to the issue help save you searching for help?)
👀 1
🙇‍♀️ 1
t
You are right that our contract tests wrongly passed before. I didn’t work much with OAS and relied on the written unit tests and mocks they used to write contract tests. Apparently, mocks were outdated, but we didn’t notice that as we used the default configuration. Thanks a lot for your help and for enforcing that setting! 😄
🙌 2
y
Fabulous, that is great feedback
t
hey @Matt (pactflow.io / pact-js / pact-go) @Yousaf Nabi (pactflow.io), me again. I think I encountered a bug in swagger-mock-validator with
allOf
notation in OAS. I prepared an example with contract and OAS files. I actually took that example from swagger.io. I’d appreciate if you have a look and share if something is wrong with the files. Run
npx @pactflow/swagger-mock-validator ./swagger.yaml ./contract.json
These are the errors I see when I run that command:
Copy code
{
      code: 'response.body.incompatible',
      message: 'Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - name',
      mockDetails: {
        interactionDescription: '46745cc6-f980-4d57-95b8-3c85539f7812',
        interactionState: '[none]',
        location: '[root].interactions[0].response.body[0]',
        mockFile: './contract.json',
        value: { name: 'Meow', petType: 'Cat' }
      },
      source: 'spec-mock-validation',
      specDetails: {
        location: '[root].paths./cats.get.responses.200.content.application/json.schema.items.allOf.0.additionalProperties',
        pathMethod: 'get',
        pathName: '/cats',
        specFile: './swagger.yaml',
        value: undefined
      },
      type: 'error'
    },
    {
      code: 'response.body.incompatible',
      message: 'Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - petType',
      mockDetails: {
        interactionDescription: '46745cc6-f980-4d57-95b8-3c85539f7812',
        interactionState: '[none]',
        location: '[root].interactions[0].response.body[0]',
        mockFile: './contract.json',
        value: { name: 'Meow', petType: 'Cat' }
      },
      source: 'spec-mock-validation',
      specDetails: {
        location: '[root].paths./cats.get.responses.200.content.application/json.schema.items.allOf.1.additionalProperties',
        pathMethod: 'get',
        pathName: '/cats',
        specFile: './swagger.yaml',
        value: undefined
      },
      type: 'error'
    }
y
Hey, thanks for the examples, I assume that is running
@pactflow/swagger-mock-validator
v11 with the default flags? I think this falls in line with the comments made by Ben Sayers here https://bitbucket.org/atlassian/swagger-mock-validator/issues/84/test-incorrectly-passes-when-mock-expects#comment-59384182 You'll note at the bottom someone advises a tool which will resolve the anyOf schemas which may make the tool perform in the way you are expecting, I've yet to try it out. Just thinking on these examples, it might be good to add these in CI, showing the output with the 4 diff combinations of flags, Looking at the spec, the only required field is
petType
but the Pact expects both?
t
yes, I’ve installed
@pactflow/swagger-mock-validator
v11 and used with the default flags.
Looking at the spec, the only required field is
petType
but the Pact expects both?
there are not
required
fields in my example. it’s just an object which consists from 2 other objects using
allOf
. Pact complains that they are both present. I assume that Pact expects them not to be present at all.
y
petType
is shown as required on line 28 of the swagger, name is not on
38
t
yeah, you are right, sorry about it. Anyway,
swagger-mock-validator
complains about both fields
y
so I assume the
allOf
is saying you can have a response with • Pet with its required field
PetType
and no name (as its optional) • Pet with its required field
PetType
and name (as its optional) Your Pact file is expecting both to be present
I will spend a bit of time on this tomorrow, as have a fair few meetings today, so really, REALLY appreciate you providing all the examples.
🙏 1
yeah, you are right, sorry about it. Anyway,
swagger-mock-validator
complains about both fields
No problem. Just want to clarify so we are on the same page 🙂
t
JIC this is from swagger.io :
allOf
takes an array of object definitions that are validated independently but together compose a single object. So, Pact file is expecting both to be present and I expect it to be the correct behaviour. https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
thank you 1
Thanks for the links you’ve shared! reading them
y
Just about to head into another meeting but if you set both fields to required in the oas spec what is the validation outcome?
t
the outcome is the same. it’s satisfied only when both of the fields are missing, like
"body": []
.