Quick question if we wanted to maintain same versi...
# general
b
Quick question if we wanted to maintain same version for the api and don’t want to introduce more mandatory fields so we are backward compatible how do we introduce those fields ( make them optional ) ?
b
You mean, how do you specify optional fields (e.g. to let people know they exist, but won't break tests)?
also: in the request or in the response? (I can imagine some different approaches)
b
Yes mainly in the request
b
In a consumer request you can specify extra fields that aren't load-bearing. It's up to the provider to care about if it needs them or not. Without that, you'd probably have trouble with the grow-then-shrink approach.
But if the provider starts responding differently based upon whether those optional fields are present or not, that'll be a breaking change (which you should notice by the contract changing).
b
So we end up versioning or keeping the required field behind a feature flag ?
b
Might be easier to explain with a concrete example.
If you're saying "the consumer will always send this field" then it's not "mandatory/required". If you're saying "the provider will always expect this new field" then it's mandatory/required and also a breaking change.
If the provider opportunistically uses an optional field, but behaves the same if its missing, then its not a breaking change.
And you can have a test for each case.
b
How about this - Add a new optional key - change the behavior based on this key present, retain the old behavior if the key doesn’t exist, and once all consumers start sending the key make it mandatory ( consumers should know once they start sending this eventually this will be made mandatory ) , if consumer wants to retain the old behavior then maintain this as optional
👍 1
@Matt (pactflow.io / pact-js / pact-go) what do you think ?
m
Might be easier to explain with a concrete example.
I agree with this point, it would be good to understand the example
also, hello again Bheem! 👋
hellothere 1
b
Yep, that sounds right. Just be aware that making it mandatory is technically a breaking change. If you have tests for the case where it's missing, they should change, and/or be removed.
👍 1