#51782 closed defect (bug) (worksforme)
Required in REST API register_rest_route args should check for empty string
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.7 |
| Component: | REST API | Keywords: | needs-patch |
| Focuses: | rest-api | Cc: |
Description
When setting required key to true in register_rest_route it will only check for the existence of the key but not if value is empty.
I think the expectation is to check for both that the key is set with a value (that is not empty) has been set.
Change History (3)
Note: See
TracTickets for help on using
tickets.
Hi @khr2003,
Welcome to trac and thanks for the ticket!
I understand this can be confusing, but it is the functionality required by the JSON Schema specification.
When you want a field to be required, and disallow an empty string, I'd recommend using the
minLengthkeyword. For example:array( 'type' => 'string', 'minLength' => 1, 'required' => true, )You can use the
minItemskeyword for arrays,minimumfor numbers, andminPropertiesfor objects.