[pve-devel] [PATCH common] JSONSchema: property strings: handle boolean default_key consistently

Dominik Csapak d.csapak at proxmox.com
Fri Sep 12 11:39:09 CEST 2025


A schema with a default_key that is of type boolean, e.g.

```
enabled => {
    type => 'boolean',
    default_key = 1,
},
```
(can be found for example in qemu-server's 'agent' property)

depending on the sent value, we handled that differently:
when sending `enabled=true`, `parse_boolean` is used to convert it to
the object:

```
{
    enabled => 1,
}
```
so our type checker is happy.

When sending `true` instead, this conversion does not happen, the
resulting object is:

```
{
    enabled => "true",
}
```
and the type check fails with

`type check ('boolean') failed - got 'true'`

To fix this, also apply this conversion in the case when the default_key
is not given.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/JSONSchema.pm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm
index d765533..c6e0f36 100644
--- a/src/PVE/JSONSchema.pm
+++ b/src/PVE/JSONSchema.pm
@@ -1090,6 +1090,9 @@ sub parse_property_string {
                 if ($format->{$key}->{default_key}) {
                     $default_key = $key;
                     if (!$res->{$default_key}) {
+                        if ($format->{$key}->{type} && $format->{$key}->{type} eq 'boolean') {
+                            $part = parse_boolean($part) // $part;
+                        }
                         $res->{$default_key} = $part;
                         last;
                     }
-- 
2.47.3





More information about the pve-devel mailing list