[pve-devel] [PATCH v3 common 2/3] JSONSchema: use validator in print_property_string too

Stefan Reiter s.reiter at proxmox.com
Thu Jun 25 13:35:40 CEST 2020


Suggested-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 src/PVE/JSONSchema.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index f987006..59a2b5a 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -1878,9 +1878,12 @@ sub generate_typetext {
 sub print_property_string {
     my ($data, $format, $skip, $path) = @_;
 
+    my $validator;
     if (ref($format) ne 'HASH') {
 	my $schema = get_format($format);
 	die "not a valid format: $format\n" if !$schema;
+	# named formats can have validators attached
+	$validator = $format_validators->{$format};
 	$format = $schema;
     }
 
@@ -1890,6 +1893,8 @@ sub print_property_string {
 	raise "format error", errors => $errors;
     }
 
+    $data = $validator->($data) if $validator;
+
     my ($default_key, $keyAliasProps) = &$find_schema_default_key($format);
 
     my $res = '';
-- 
2.20.1





More information about the pve-devel mailing list