๐ ๐ฆ๐๐ผ๐ฝ๐ฝ๐ฒ๐ฑ ๐๐ผ๐น๐น๐ผ๐๐ถ๐ป๐ด ๐๐ฃ๐ ๐๐ฒ๐๐ ๐ฃ๐ฟ๐ฎ๐ฐ๐๐ถ๐ฐ๐ฒ๐
I followed standard API rules for years. I used DTOs. I used validation constraints. I followed the guides. It looked clean. It failed in real projects.
Most guides assume your data model is stable. They think a customer always has a name. They think an order always has a status. Real business is not like this.
I worked for a large company. Requirements changed every week. New fields appeared. Old fields stayed for legacy clients.
Updating DTOs took too much time.
- I updated the DTO.
- I updated the validator.
- I updated the serializer.
- I updated the documentation.
I solved the wrong problem. I tried to model the business. I should have defined the API contract.
A contract asks one thing: What payload is valid today?
I switched to JSON Schema. It does not care about object hierarchies. It describes data.
Now I start with the contract. I update the schema when requirements change. I do not touch an entire object graph. I do not fight a DTO hierarchy.
Stable patterns emerge over time. Then I move those patterns into the domain.
DTOs are great tools. But they are not the starting point for unstable requirements. Start with the contract. It reflects reality.
How do you handle changing data?
Source: https://dev.to/outcomer/i-stopped-following-api-validation-best-practices-heres-why-1fmj