print api res: always allow result to be undef if optional

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>
This commit is contained in:
Thomas Lamprecht 2019-05-13 06:52:19 +00:00
parent b610385849
commit c0b8717c44

View File

@ -413,6 +413,7 @@ sub print_api_result {
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 };