Eddie Stanley
08/01/2024, 10:33 PM{
animalType: "Cat" | "Dog" | "Mouse"
}
then we need it to be a breaking change if the provider might start returning an animalType of "Giraffe".
As far as I know, there's no real solution for that with consumer-driven contract testing. The consumer contract can say
animalType: regex('Cat|Dog|Mouse', 'Dog'),
That will result in a contract-by-example having "Dog". But when the provider evaluates itself against that contract, the evaluation will succeeed so long as the test doesn't set the animalType to "Giraffe" (even though it could in production).
We're wondering - does switching to bi-directional contract testing solve this problem? If the provider publishes an OAS schema that says (under version 2.0.1 of the provider) animalType can now take on a value of "Giraffe", that version of the provider is incompatible with the consumer?Eddie Stanley
08/02/2024, 3:32 AMMatt (pactflow.io / pact-js / pact-go)
Eddie Stanley
08/02/2024, 4:14 AMEddie Stanley
08/02/2024, 4:15 AMMatt (pactflow.io / pact-js / pact-go)
Eddie Stanley
08/02/2024, 4:25 AMIf you can guarantee the schema is always correct (e.g. by generating it from types or something) then perhaps you could give some additional confidenceYeah I think this is the approach we'll probably take ⢠Start with a JSON schema ⢠Using SourceGenerators (C#) on the provider side, create C# types from the schema ⌠C# codebase will use the generated types ⢠Use some tool to generate TypeScript types from the schema on the client side ⌠TS codebase will use the generated types ⢠Do something (possibly as part of the contract) to ensure the schema versions are the same â
What problem are you actually trying to solve, thoughOur consumer is uploading a document to be processed/transformed. The provider returns a response based on the uploaded document; the consumer needs to fully understand the response it got back (transformation result). If the consumer can't support a given transformation / aspect of the result, the provider shouldn't generate it until the consumer has been updated to handle it.
Eddie Stanley
08/02/2024, 4:26 AMBas Dijkstra
08/02/2024, 5:55 AMGiraffe as an animalType?
Because to me, this doesnât sound like a case that should be covered through a contract test but rather by provider-side testing of the implementation.
But of course, that also means youâll have to trust the provider to do that type of testing.Matt (pactflow.io / pact-js / pact-go)