This chapter covers
- Validating function arguments
- Validating function return values
- Data validation beyond static types
- Automatic generation of data model diagrams
- Automatic generation of schema-based unit tests
As the size of a codebase grows in a project that follows Data-Oriented Programming principles, it becomes harder to manipulate functions that receive and return only generic data. It is hard to figure out the expected shape of the function arguments and when we pass invalid data, we don’t get meaningful errors.
Until now, we have illustrated how to validate data at system boundaries. In this chapter, we illustrate how to validate data when it flows inside the system by defining data schemas for function arguments and their return values. This allows us to make explicit the expected shape of function arguments and it eases development. We gain some additional benefits from this endeavor like automatic generation of data model diagrams and schema-based unit tests.
Dave’s first task is to implement a couple of new HTTP endpoints: downloading the catalog as a CSV file, searching books by author, rating books. Once he is done with the task, Dave calls Theo for a code review.
Warning
The involvement of Dave in the Klafim project is explained in the opener for Part 3. Please take a moment to read the opener if you missed it.
THEO: Was it difficult to get your head around the DOP code?