[wp-trac] [WordPress Trac] #51025: Add support for the anyOf and oneOf JSON Schema keywords.

WordPress Trac noreply at wordpress.org
Sat Aug 15 14:36:58 UTC 2020


#51025: Add support for the anyOf and oneOf JSON Schema keywords.
-------------------------+-------------------------------------------------
 Reporter:               |      Owner:  (none)
  TimothyBlynJacobs      |
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  5.6
Component:  REST API     |    Version:
 Severity:  normal       |   Keywords:  needs-patch needs-unit-tests json-
  Focuses:               |  schema
-------------------------+-------------------------------------------------
 These would be particularly helpful for the Image Editor Batch API:
 https://github.com/WordPress/gutenberg/pull/23369

 Reference: https://tools.ietf.org/html/draft-fge-json-schema-
 validation-00#section-5.5.4

 One of the tricky things is how to handle error messages. For an example
 schema:


 {{{
 {
   "type": "array",
   "items": {
     "oneOf": [
       {
         "type": "object",
         "properties": {
           "operation": {
             "type": "string",
             "enum": [
               "crop"
             ]
           },
           "x": {
             "type": "integer"
           },
           "y": {
             "type": "integer"
           }
         }
       },
       {
         "type": "object",
         "properties": {
           "operation": {
             "type": "string",
             "enum": [
               "rotate"
             ]
           },
           "degrees": {
             "type": "integer",
             "minimum": 0,
             "maximum": 360
           }
         }
       }
     ]
   }
 }
 }}}

 If the user submitted this data:

 {{{
 [
 {
   "operation": "rotate",
   "degrees": 450
 }
 ]
 }}}

 You want to be able to give an error like "degrees must be greater than 0
 and less than 360". But the most simple validation approach would give an
 error like "did not match against exactly one schema".

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51025>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list