]> git.proxmox.com Git - pve-common.git/commitdiff
print api res: always allow result to be undef if optional
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 13 May 2019 06:52:19 +0000 (06:52 +0000)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 13 May 2019 06:52:28 +0000 (06:52 +0000)
If the return schema says that it's optionally returns something then
we want to allow returning nothing, i.e., undef

Co-developed-by: Dominic Jäger <d.jaeger@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/CLIFormatter.pm

index e886db5797ccdb06b8fb5a81d77cefb5b5337e7d..84dbed1e6e2af6fbaf63c2e7d3631247f94bd664 100644 (file)
@@ -413,6 +413,7 @@ sub print_api_result {
 
     if ($result_schema && defined($result_schema->{type})) {
        return if $result_schema->{type} eq 'null';
 
     if ($result_schema && defined($result_schema->{type})) {
        return if $result_schema->{type} eq 'null';
+       return if $result_schema->{optional} && !defined($data);
     } else {
        my $type = $guess_type->($data);
        $result_schema = { type => $type };
     } else {
        my $type = $guess_type->($data);
        $result_schema = { type => $type };