Hidden listing
function KlipseLoadLib(url, symbol) { if (window[symbol]) { return; } var script = document.createElement('script'); script.src = url; document.body.append(script); } KlipseLoadLib("https://cdnjs.cloudflare.com/ajax/libs/ajv/6.12.6/ajv.bundle.js", "Ajv"); KlipseLoadLib("https://cdnjs.cloudflare.com/ajax/libs/json-schema-faker/0.5.0-rc23/bundle.umd.min.js", "JSONSchemaFaker"); function dev() { return true; } window.ajv = new Ajv();
As the size of a code base grows in a project that follows DOP 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 will 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, such as automatic generation of data model diagrams and schema-based unit tests.