Open
Description
I don't write objects with optional properties most of the time. I tend to prefer to use polymorphism to allow one of several data structures. When I do have an optional field, it's often something like "comments" or "extra info", and even then I don't have any philosophical objection to simply making it required but allowing it to contain the empty string.
An optional
keyword to complement required
would greatly benefit me (and hopefully others), without treading on the toes of people who are writing schemata with many optional values.
My proposition is thus:
- Either
required
oroptional
may be provided - It is an error to provide both
- The default remains as it is (everything optional), which is the same as providing
required
with an empty array - If
optional
is provided, anything not mentioned is now required - Passing an empty array to
optional
means everything is required
Hope that's both clear and a useful idea.