pact-foundation / pact-net

.NET 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://pact.io
MIT License
846 stars 232 forks source link

Verify just a string json #409

Closed renato04 closed 2 years ago

renato04 commented 2 years ago

Hi!

I'd like to test just a string JSON against the swagger definition. Is there a way to achieve that with Pact.Net?

Thank you!

YOU54F commented 2 years ago

Hi @renato04,

Could you expand on your use case please, with examples, thank you!

Pact.Net will allow you to create a Pact consumer contract file and alone is agnostic about an OpenAPI definition which would describe a provider API's behaviour.

renato04 commented 2 years ago

Hi @YOU54F

The architect team designed the OpenApi's definition before it gets developed. So we need a way to validate if the developer's team had developed the API correctly based on some responses from this API against the OpenApi definition.

We need to test the contract without a running API. Just verify a JSON response complies with an OpenApi definition.

YOU54F commented 2 years ago

https://docs.pactflow.io/docs/examples/bi-directional/provider/dotnet/

The above sample repo shows Pact.NET being used to generate a consumer contract, and utilises Pactflow to allow the provider to upload an OpenAPI spec.

There is a compatible provider to see the flow end to end

renato04 commented 2 years ago

Thank you @YOU54F!

Must I have a PactFlow subscription to achieve that?

YOU54F commented 2 years ago

To be able to upload OAS contracts, to a Pactflow broker, you would indeed need a Pactflow subscription, that feature is not present in the Open Source Pact Broker. The starter plan is free, so up to you :)

There is open source tooling available which will allow you to compare pacts against OpenAPI specifications, which you can use in your workflow.

https://bitbucket.org/atlassian/swagger-mock-validator/src/master/

Pactflow uses a fork of the above as part of Bi-Directional Contract testing.

Feel free to jump on our Pact Slack group if you haven't already, everyone is really friendly and open to chatting https://slack.pact.io

The architect team designed the OpenApi's definition before it gets developed. So we need a way to validate if the developer's team had developed the API correctly based on some responses from this API against the OpenApi definition.

The use case is aligned with my way of thinking, and incorporating it nicely with a consumer driven contract testing flow to complete the loop is on my agenda, as I would be nice to show about BDCT/CDCT compliment each other!