]> git.proxmox.com Git - pve-common.git/commit
JSONSchema: add format validator support and cleanup check_format
authorStefan Reiter <s.reiter@proxmox.com>
Thu, 25 Jun 2020 11:35:39 +0000 (13:35 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Mon, 6 Jul 2020 08:40:10 +0000 (10:40 +0200)
commit70fdc0501bf90c598bb8e9eb7f3fe3b64c7f8722
tree3f8e16922be53b551bd3b02345ab9e1dbcabe375
parent37c7daf0d43299e10b504f550412292edadf8ff2
JSONSchema: add format validator support and cleanup check_format

Adds a third, optional parameter to register_format that allows specifying
a function that will be called after parsing and can validate the parsed
data. A validator should die on failed validation, and can also change the
parsed object by returning a modified version of it.

This is useful so one can register a format with its hash, thus allowing
documentation to be generated automatically, while still enforcing certain
validation rules.

The validator only needs to be called in parse_property_string, since
check_format always calls parse_property_string if there is a
possibility of a validator existing at all. parse_property_string should
then be called with named formats for best effect, as only then can
validators be used.

Clean up 'check_format' as well (which pretty much amounts to a rewrite).
No existing functionality is intentionally changed.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
src/PVE/JSONSchema.pm