[wp-trac] [WordPress Trac] #51782: Required in REST API register_rest_route args should check for empty string
WordPress Trac
noreply at wordpress.org
Mon Nov 16 03:38:56 UTC 2020
#51782: Required in REST API register_rest_route args should check for empty string
--------------------------+-------------------------
Reporter: khr2003 | Owner: (none)
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: REST API | Version: 4.7
Severity: normal | Resolution: worksforme
Keywords: needs-patch | Focuses: rest-api
--------------------------+-------------------------
Changes (by TimothyBlynJacobs):
* status: new => closed
* version: 5.5.3 => 4.7
* resolution: => worksforme
* milestone: Awaiting Review =>
Comment:
Hi @khr2003,
Welcome to trac and thanks for the ticket!
I understand this can be confusing, but it is the functionality required
by the [https://tools.ietf.org/html/draft-fge-json-schema-
validation-00#section-5.4.3 JSON Schema specification].
When you want a field to be required, and disallow an empty string, I'd
recommend using the `minLength` keyword. For example:
{{{#!php
array(
'type' => 'string',
'minLength' => 1,
'required' => true,
)
}}}
You can use the `minItems` keyword for arrays, `minimum` for numbers, and
`minProperties` for objects.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51782#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list