public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common] JSONSchema: property strings: handle boolean default_key consistently
Date: Fri, 12 Sep 2025 11:39:09 +0200	[thread overview]
Message-ID: <20250912093919.1715010-1-d.csapak@proxmox.com> (raw)

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@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



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


                 reply	other threads:[~2025-09-12  9:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250912093919.1715010-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal