Opened 7 weeks ago
#51911 new enhancement
REST API: Make JSON Schema enum more robust for non-string types
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | needs-patch good-first-bug json-schema |
Focuses: | Cc: |
Description
The enum
JSON schema keyword allows for enforcing that the provided value is one of the listed values. This can be used with any type of value. Our implementation, however, doesn't apply the same type coercion when doing regular validation.
In other words, for an enum of [ 0, 1 ]
I should be able to pass "1"
.
To do this, I think we might want to move the enum
validation to the end of rest_validate_value_from_schema
so that type validation has already been applied, and then either call rest_sanitize_value_from_schema
before passing the value to the enum
check, or just do the type casting.
We'll also need to pay special care to arrays/objects applying rest_stabilize_value
and making sure that the type safe in_array()
check has the correct JSON semantics.