3 ms·
The problem here as I understood it is more general and orthogonal to what the Parse, Don't Validate article is talking about. 1. A field being "required", is
by dgb23 2y ago
The problem here as I understood it is more general and orthogonal to what the Parse, Don't Validate article is talking about.
1. A field being "required", is not a property of the field itself, but of the construct holding the field. JSON-Schema does this correctly, by letting you define an array of required fields on the schema of an object instead of it being a property of a specific field.
2. Consumers, not producers should decide what their assumptions are. Producers should decide what their guarantees are.
3. Everyone, including the parts in the middle (here it's a message bus) should only state assumptions that they actually need in order to function. Use different schemas for different assumptions (which is easier to do if the "required" assumption is a property of a construct and not a field).
The example in the article you mentioned illustrates nicely how these three principles are broken by "required" (or maybe how Protocol Buffers are used in general).
- zigzag312 2y ago> 2. Consumers, not producers should decide what their assumptions are. Producers should decide what their guarantees are. Issue with schema definition languages is that only one set classes is generated. Forcing consumers to create large amounts of mapping logic to transform input to objects with required assumptions. I like the idea of an array of required fields on the schema of an object. Using arrays of required fields, could be used to generate different set of classes. That would make writing near-duplicate classes of input objects and mapping logic unnecessary.