]> git.proxmox.com Git - pve-common.git/commit - src/PVE/RESTHandler.pm
JSONSchema: add support for array parameter in api calls, cli and config
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 6 Jun 2023 13:08:45 +0000 (15:08 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Jun 2023 11:10:50 +0000 (13:10 +0200)
commit07f136d636a16f298622482ed7ba9cc709c6cdd7
treee3b0198fd43aba57233ac306aedb3823c7ac6cc0
parent7bbfaff1e089ced8876da43a34e962aa198cc491
JSONSchema: add support for array parameter in api calls, cli and config

a few things were missing for it to work:
* on the cli, we have to get the option as an array if the type is an
  array
* the untainting must be done recursively, otherwise, the regex matching
  converts an array hash into the string 'ARRAY(0x123412341234)'
* JSONSchema::parse_config did not handle array formats specially, but
  we want to allow to specify them multiple time
* the biggest point: in the RESTHandler, to be compatible with the
  current gui behavior, we have to rewrite two parameter types:
  - when the api defines a '-list' format for a string type, but we get
    a list (because of the changes in http-server), we join the list
    with a comma into a string
  - when the api defines an 'array' type, but we get a scalar value,
    wrap the value in an array (because for www-form-urlencoded, you
    cannot send an array with a single value) add tests for this
    behavior, some of which we want to deprecate and remove in the
    future

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/JSONSchema.pm
src/PVE/RESTHandler.pm
test/Makefile
test/api_parameter_test.pl [new file with mode: 0755]