#51782 closed defect (bug) (worksforme)
Required in REST API register_rest_route args should check for empty string
| Reported by: | khr2003 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | REST API | Version: | 4.7 |
| Severity: | normal | Keywords: | needs-patch |
| Cc: | Focuses: | rest-api |
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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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:You can use the
minItemskeyword for arrays,minimumfor numbers, andminPropertiesfor objects.