pactflow / pact-msw-adapter

Create MSW (mock-service-worker) mocks, and generate pact contracts from the recorded interactions.
MIT License
45 stars 15 forks source link

Pactflow Bidirectional contract test fails in case of OneOf /AllOf in Open API spec file though the consumer pact is as per the spec file #44

Closed tl-madhulika-mitra closed 2 years ago

tl-madhulika-mitra commented 2 years ago

Consumer: Cypress+MSW - Generated Pact file Provider - Open API Specification Using Pact broker

The response structure schema looks like this:

_GetStatusDetails{ oneOf -> #/components/schemas/Authorization Required{...}#/components/schemas/Authorizing{...}#/components/schemas/Authorized{...}#/components/schemas/Executed{...}#/components/schemas/Settled{...}#/components/schemas/Failed{...}_

In the consumer pact file - we have added the required interaction for Authorization Required status.

On comparison all the fields error out and Response Body Is Incompatible Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - id

Mismatched Pact Path: [root].interactions[0].response.body Mismatched Provider Path: [root].paths./status/{id}.get.responses.200.content.application/json; charset=UTF-8.schema.additionalProperties.

Similarly when our schemas had "AllOf" also , we encounter a failure. Once we remove these and make a simple response body which does not nest further, we are able to proceed.

Kindly let us know if there is an open issue for this or is there some specification we need to mention. I did not post this to slack, since after a lot of retries and check I do feel there is some issue here. But please correct me if im wrong :)

YOU54F commented 2 years ago

Hey @tl-madhulika-mitra, thanks for the message (and using the tool)

The validation is being performed by this tool - which is a fork of atlassians https://bitbucket.org/atlassian/swagger-mock-validator

A change in default behaviour was introduced

This thread is worth a read and it will provide some reasoning as to the issues in validation for allOf, anyOf and oneOf

https://bitbucket.org/atlassian/swagger-mock-validator/issues/84/test-incorrectly-passes-when-mock-expects

Using Pact broker

Just to confirm, you are using the Pactflow broker, not the OSS broker

tl-madhulika-mitra commented 2 years ago

Thank you @YOU54F . Yes we are using Pactflow broker.

tl-madhulika-mitra commented 2 years ago

@YOU54F - Also 2 follow up issues is

Without setting any additional properties

setting any additional properties:true

YOU54F commented 2 years ago

If you could provide some code examples illustrating the points and the pact/specs in question, it would help tremendously in visualising.

We can collate the various examples to illustrate the points, you can see some in the readme on this page.

You would just need a sample pact file and swagger file, and you can show the output with the different combination of flags.

YOU54F commented 2 years ago

Hey @tl-madhulika-mitra

Docs updated here

https://docs.pactflow.io/docs/bi-directional-contract-testing/contracts/oas#allof-support-and-other-logical-keywords

and this issue would be best tracked against this repo

https://github.com/pactflow/swagger-mock-validator/issues?q=is%3Aopen+is%3Aissue

where we would hope to be able to address this in the future

tl-madhulika-mitra commented 2 years ago

Thanks @YOU54F . Could you please clarify where do we add the "additionalPropertiesInResponse":true - when we are using pactflow, I tried to refer this , but not super clear where to add this setting.