(repeating a slightly augmented reply to Gabriel that accidentally
went off-list)
On Mon, Feb 3, 2014 at 4:26 PM, Gabriel Castillo <
gab...@uglymunky.com> wrote:
> While I haven't had to deal with validation that is extra-ordinarily
> complex, In times when we have had to create properties that are objects
> (instead of making them entities) we have made each property of the object a
> field.
>
> fields = [
> {name: door.color, type: text}
> , {name: door.height, type: number}
> , {name: door.width, type: number}
> ]
Indeed this is a good strategy for nested records when the structure
is static. However, consider something like a variant record where
the presence of a field should exclude the presence of (some) others.
Perhaps even something involving recursive variant record types: the
API I’m working on has a resource with a property that is actually a
JSON-encoded logic expression AST. (I do think it’s a bit of a stretch
to think Siren’s validation specification should handle something like
this, but it’s worth thinking about this sort of structural validation
even if it’s impractical to make it this expressive.)
Consider also fields whose values should be one of a fixed (or
server-provided) set of values, such as in an enumerated type, or a
select HTML control. This is very common in Web forms. This is
indeed addressed by your options proposal, at least if the set of
options can be described as simple text values — but it might be
desirable to provide a title for presentation along with the actual
field value.
Consider even fields whose values should be one of a set of values
known by the server, but with a large set of possible values that
could change depending on the state of resources in the server, such
that it would be bad to include the full enumeration of options in the
action field type: in my use case, field values sometimes are the
URIs of resources included in some collection. This could be
modeled somewhat easily by providing the URI for the collection
resource as the field type, and clients could then query the collection
resource for linked or embedded resources with, say, the `item`
relation type, to procure the valid potential values for such a field.
This is what I mean by the distinction between how to validate,
and how to procure valid values: instead of informing the client of
how to decide whether user input forms an acceptable value for a
field, perhaps the server ought to inform the client how to ask for
or search for values that are valid, perhaps in ways that make more
sense for a given application than “here’s a (possibly huge) list of
every valid thing you may provide for this field”.
I insist that these are just some random ideas inspired by the API I’m
currently working on, and I’m not convinced (or trying to convince
anyone) that it’s wise for Siren itself to support specifying field
types with this degree of detail. I suspect in many cases it could be
easier to solve this sort of issue with a more granular definition of
resources for the API. I do dream of a full algebraic type
specification format for the Web, though :)