What Makes a Change Breaking
Most lists of breaking changes are lists of verbs. Removing is breaking, adding is safe. They are wrong about half the time, because they ignore which way the data flows.
Direction decides
A request is written by the client and read by the server. A response is written by the server and read by the client. A change is safe when the reader still accepts everything the writer may send:
- in a request, the new schema must accept everything the old one did;
- in a response, the old schema must accept everything the new one may return.
One relation, applied in two directions. Everything else follows from it.
| change | in a request | in a response |
|---|---|---|
| a field becomes optional | safe | breaking |
| a field becomes required | breaking | safe |
| a one-of gains a branch | safe | breaking |
| a one-of loses a branch | breaking | safe |
| a number becomes a string | breaking | breaking |
Here is the one that slips through review most often. The response used to say:
and now it says:
It looks like an addition, and it is. Every client that reads payment.last4
is now one wallet payment away from a crash. Papi reports it as
payment can now be Wallet.
Open or closed objects
Whether an extra field breaks a client depends on the client. Most ignore fields they do not know; some reject them. Papi assumes the tolerant reader by default and lets you switch to the strict one under View › Open objects, because it is a question about your consumers, not about the spec.
Things that look breaking and are not
- Renaming
/users/:idto/users/:user_id. A parameter name is yours, not the client’s. The client sends a value in a position. - Reordering fields. Same object.
- Removing authentication from an endpoint.
- A new endpoint, or a new response code.
Things that look harmless and are not
- Adding a required query parameter.
- Adding authentication to an endpoint that had none.
- Removing a response code a client has learned to handle.
- Editing an entity three references deep inside a response. Papi expands every endpoint all the way down before judging it, so the change is found where it lands, not where it was typed.
Papi tells you; it does not stop you
Breaking a contract is sometimes the right call. Papi never blocks a merge over
it. It lists every reason on the candidate, and the version number records the
decision. In CI, papi check exits with status 2 when a candidate would break
its clients, if you want a gate of your own.