You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: extending-the-rest-api/schema.md
+61-61Lines changed: 61 additions & 61 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -364,6 +364,67 @@ array(
364
364
);
365
365
```
366
366
367
+
### Strings
368
+
369
+
The `string` types supports three additional keywords.
370
+
371
+
#### minLength and maxLength
372
+
373
+
The `minLength` and `maxLength` keywords can be used to constrain the acceptable length of a string. Importantly multi-byte characters are counted as a single character and bounds are inclusive.
374
+
375
+
For instance, given the following schema, `ab`, `abc`, and `abcd` are valid, while `a`, and `abcde` are invalid.
376
+
377
+
```php
378
+
array(
379
+
'type' => 'string',
380
+
'minLength' => 2,
381
+
'maxLength' => 4,
382
+
);
383
+
```
384
+
385
+
The `exclusiveMinimum` and `exclusiveMaximum` keywords do not apply, they are only valid for numbers.
386
+
387
+
#### pattern
388
+
389
+
The JSON Schema keyword `pattern` can be used to validate that a string field matches a regular expression.
390
+
391
+
For instance, given the following schema, `#123` would be valid, but `#abc` would not.
392
+
393
+
```php
394
+
array(
395
+
'type' => 'string',
396
+
'pattern' => '#[0-9]+',
397
+
);
398
+
```
399
+
400
+
### Numbers
401
+
402
+
The `number` and `integer` types support four additional keywords.
403
+
404
+
#### minimum and maximum
405
+
406
+
The `minimum` and `maximum` keyword allow constraining the range of acceptable numbers. For example, `2` would be valid according to this schema, but `0` and `4` would not be.
407
+
408
+
```php
409
+
array(
410
+
'type' => 'integer',
411
+
'minimum' => 1,
412
+
'maximum' => 3,
413
+
);
414
+
```
415
+
416
+
JSON Schema also allows using the `exclusiveMinimum` and `exclusiveMaximum` keywords to denote that the value cannot equal the defined `minimum` or `maximum` respectively. For example, in this case only `2` would be an acceptable value.
417
+
418
+
```php
419
+
array(
420
+
'type' => 'integer',
421
+
'minimum' => 1,
422
+
'exclusiveMinimum' => true,
423
+
'maximum' => 3,
424
+
'exclusiveMaximum' => true,
425
+
);
426
+
```
427
+
367
428
### Arrays
368
429
369
430
Specifying a `type` of `array` requires data to be an array, but that is only half the validation story. You'll also want to enforce the format of each item in the array. This is done by specifying a JSON Schema that each array item must conform to using the `items` keyword.
@@ -723,67 +784,6 @@ While this would fail validation.
723
784
}
724
785
```
725
786
726
-
### Numbers
727
-
728
-
The `number` and `integer` types support four additional keywords.
729
-
730
-
#### minimum and maximum
731
-
732
-
The `minimum` and `maximum` keyword allow constraining the range of acceptable numbers. For example, `2` would be valid according to this schema, but `0` and `4` would not be.
733
-
734
-
```php
735
-
array(
736
-
'type' => 'integer',
737
-
'minimum' => 1,
738
-
'maximum' => 3,
739
-
);
740
-
```
741
-
742
-
JSON Schema also allows using the `exclusiveMinimum` and `exclusiveMaximum` keywords to denote that the value cannot equal the defined `minimum` or `maximum` respectively. For example, in this case only `2` would be an acceptable value.
743
-
744
-
```php
745
-
array(
746
-
'type' => 'integer',
747
-
'minimum' => 1,
748
-
'exclusiveMinimum' => true,
749
-
'maximum' => 3,
750
-
'exclusiveMaximum' => true,
751
-
);
752
-
```
753
-
754
-
### Strings
755
-
756
-
The `string` types supports three additional keywords.
757
-
758
-
#### minLength and maxLength
759
-
760
-
The `minLength` and `maxLength` keywords can be used to constrain the acceptable length of a string. Importantly multi-byte characters are counted as a single character and bounds are inclusive.
761
-
762
-
For instance, given the following schema, `ab`, `abc`, and `abcd` are valid, while `a`, and `abcde` are invalid.
763
-
764
-
```php
765
-
array(
766
-
'type' => 'string',
767
-
'minLength' => 2,
768
-
'maxLength' => 4,
769
-
);
770
-
```
771
-
772
-
The `exclusiveMinimum` and `exclusiveMaximum` keywords do not apply, they are only valid for numbers.
773
-
774
-
#### pattern
775
-
776
-
The JSON Schema keyword `pattern` can be used to validate that a string field matches a regular expression.
777
-
778
-
For instance, given the following schema, `#123` would be valid, but `#abc` would not.
779
-
780
-
```php
781
-
array(
782
-
'type' => 'string',
783
-
'pattern' => '#[0-9]+',
784
-
);
785
-
```
786
-
787
787
The regex is not automatically anchored. Regex flags, for instance `/i` to make the match case insensitive are not supported.
788
788
789
789
The JSON Schema RFC recommends limiting yourself to the following regex features so the schema can be interoperable between as many different programming languages as possible.
0 commit comments