▲ | hxtk 5 days ago | |
The main “why” that I find is that it allows you to intentionally design your API types and know when a change is touching them. I worked on a project with a codebase on the order of millions of lines, and many times a response was made by taking an ORM object or an app internal data structure and JSON serializing it. We had a frequent problem where we’d make some change to how we process a data structure internally and oops, breaking API change. Or worse yet, sensitive data gets added to a structure typically processed with that data, not realizing it gets serialized by a response handler. It was hard to catch this in code review because it was hard to even know when a type might be involved in generating a response elsewhere in the code base. Switching to a schema-first API design meant that if you were making a change to a response data type, you knew it. And the CODEOWNERS file also knew it, and would bring the relevant parties into the code review. Suddenly those classes of problems went away. |