add typetext property for more complex types
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 5 Sep 2016 05:47:32 +0000 (07:47 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 5 Sep 2016 05:47:32 +0000 (07:47 +0200)
src/PVE/RESTHandler.pm

index 0b8b81c..fc220a6 100644 (file)
@@ -40,7 +40,16 @@ sub api_clone_schema {
                    next; # only handle once for -xx0, but only if -xx0 exists
                }
            }
-           $res->{$k}->{$p} = ref($pd) ? clone($pd) : $pd;
+           my $tmp = ref($pd) ? clone($pd) : $pd;
+           # NOTE: add typetext property for more complex types, to
+           # make the web api viewer code simpler
+           if (!(defined($tmp->{enum}) || defined($tmp->{pattern}))) {
+               my $typetext = PVE::JSONSchema::schema_get_type_text($tmp);
+               if ($tmp->{type} && ($tmp->{type} ne $typetext)) {
+                   $tmp->{typetext} = $typetext;
+               }
+           }
+           $res->{$k}->{$p} = $tmp;
        }
     }