Clarify whether repeated type references are allowed for the sum-type constraints #53
Labels
requires new version
Something that should be considered for next version of the Ion Schema Specification
The spec defines the behavior of the sum-type constraints (
one_of
,any_of
,all_of
) in terms ofTypes
, without any particular mention of the behavior in relation toTYPE_REFERENCE
s (ie. the grammar of the constraint argument). This is a non-obvious distinction, but I think most people would instantly be familiar with it when framed a different way.There are two choices (type references) presented here, but they point to the same thing (type).
The Ion Schema spec does not mention whether the type references may be repeated or how an implementation should handle a repeated type reference for one of these constraints.
As of
ion-schema-kotlin-1.1
, the schema system will allow you to repeat a type reference in the argument forall_of
,one_of
, andany_of
. For example, in theion-schema-kotlin
implementation, both of these are valid type definitions:In this case, they are functionally equivalent in
ion-schema-kotlin
. It would also be functionally equivalent to do the same thing withall_of
. However, repeated type references inone_of
actually lead to unsatisfiable conditions inion-schema-kotlin
. For example:In this case,
train_or_truck
will only be satisfied if the value matchestruck
—if it were to matchtrain
it would match two type references and be invalid for theone_of
constraint. The typecar_or_boat
is completely unsatisfiable because all values will match either 0 or 2 of the type references (or 4 type references if it's an Amphicar).So, for
any_of
andall_of
, repeated type references are redundant but harmless, whereas forone_of
they change the satisfiability of the constraint.Why does this matter?
There is no legitimate use case for having repeated type references in any of these three constraints, so if someone is adding repeated type references to one of these constraints, they have made a mistake. Since it is always considered a mistake, something should be done to prevent or mitigate this mistake, especially in the case of
one_of
.The spec should be updated to say that the argument for the sum-type constraints is a set of type references, but that it's modeled as a list because Ion does not have any set type. In addition, the spec should...
The text was updated successfully, but these errors were encountered: