|
760 | 760 | to the assertion.
|
761 | 761 | </t>
|
762 | 762 | <t>
|
763 |
| - For example, the "maxLength" keyword from the companion validation |
764 |
| - vocabulary will only restrict certain strings |
| 763 | + For example, the "maxLength" keyword from the companion |
| 764 | + <xref target="json-schema-validation">validation vocabulary</xref>: |
| 765 | + will only restrict certain strings |
765 | 766 | (that are too long) from being valid. If the instance is a number,
|
766 | 767 | boolean, null, array, or object, then it is valid against this assertion.
|
767 | 768 | </t>
|
| 769 | + <t> |
| 770 | + This behavior allows keywords to be used more easily with instances |
| 771 | + that can be of multiple primitive types. The companion validation |
| 772 | + vocabulary also includes a "type" keyword which can independently |
| 773 | + restrict the instance to one or more primitive types. This allows |
| 774 | + for a concise expression of use cases such as a function that might |
| 775 | + return either a string of a certain length or a null value: |
| 776 | + </t> |
| 777 | + <figure> |
| 778 | + <artwork> |
| 779 | +<![CDATA[ |
| 780 | +{ |
| 781 | + "type": ["string", "null"], |
| 782 | + "maxLength": 255 |
| 783 | +} |
| 784 | +]]> |
| 785 | + </artwork> |
| 786 | + <postamble> |
| 787 | + If "maxLength" also restricted the instance type to be a string, |
| 788 | + then this would be substantially more cumbersome to express because |
| 789 | + the example as written would not actually allow null values. |
| 790 | + Each keyword is evaluated separately unless explicitly specified |
| 791 | + otherwise, so if "maxLength" restricted the instance to strings, |
| 792 | + then including "null" in "type" would not have any useful effect. |
| 793 | + </postamble> |
| 794 | + </figure> |
768 | 795 | </section>
|
769 | 796 | </section>
|
770 | 797 |
|
|
0 commit comments