public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pdm-devel] [PATCH proxmox 0/2] schema2rust: use 'pattern' if specified
@ 2025-10-01 15:47 Hannes Laimer
  2025-10-01 15:47 ` [pdm-devel] [PATCH 1/2] schema2rust: extract pattern validation from nested API schema fields Hannes Laimer
  2025-10-01 15:47 ` [pdm-devel] [PATCH 2/2] pve-api-types: regenerate Hannes Laimer
  0 siblings, 2 replies; 3+ messages in thread
From: Hannes Laimer @ 2025-10-01 15:47 UTC (permalink / raw)
  To: pdm-devel

Commit message itself contains some context. With this change we end up
with quite a few new generated regexe's/patterns, so I included the
regenerated types.rs.

Hannes Laimer (2):
  schema2rust: extract pattern validation from nested API schema fields
  pve-api-types: regenerate

 pve-api-types/generator-lib/Schema2Rust.pm |  27 +++-
 pve-api-types/src/generated/types.rs       | 168 +++++++++++++++++++++
 2 files changed, 192 insertions(+), 3 deletions(-)

-- 
2.47.3



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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pdm-devel] [PATCH 1/2] schema2rust: extract pattern validation from nested API schema fields
  2025-10-01 15:47 [pdm-devel] [PATCH proxmox 0/2] schema2rust: use 'pattern' if specified Hannes Laimer
@ 2025-10-01 15:47 ` Hannes Laimer
  2025-10-01 15:47 ` [pdm-devel] [PATCH 2/2] pve-api-types: regenerate Hannes Laimer
  1 sibling, 0 replies; 3+ messages in thread
From: Hannes Laimer @ 2025-10-01 15:47 UTC (permalink / raw)
  To: pdm-devel

Previously, pattern validation was only extracted from top-level string fields,
leaving nested pattern fields and array item patterns unprocessed. This change
enables pattern extraction from nested schema structures, ensuring regex
validation is generated for all pattern fields regardless of their depth.
The generated Rust code now includes const_regex! definitions and
ApiStringFormat::Pattern references for previously ignored pattern fields.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 pve-api-types/generator-lib/Schema2Rust.pm | 27 +++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/pve-api-types/generator-lib/Schema2Rust.pm b/pve-api-types/generator-lib/Schema2Rust.pm
index 0f3efc0a..794c7abe 100644
--- a/pve-api-types/generator-lib/Schema2Rust.pm
+++ b/pve-api-types/generator-lib/Schema2Rust.pm
@@ -206,6 +206,25 @@ my sub print_struct : prototype($$$) {
 
     my @arrays;
 
+    # Collect array fields
+    for my $field (sort keys $def->{fields}->%*) {
+        my $field_def = $def->{fields}->{$field};
+        if ($field_def->{kind} eq 'array-field') {
+            push @arrays, $field_def;
+        }
+    }
+
+    # Add regex constants from array fields to the main struct's API object
+    for my $array (@arrays) {
+        my $type_name = $array->{array_type_name};
+        next if $done_array_types->{$type_name};
+        if ($API && $array->{api}->{-regexes}) {
+            for my $name (keys %{$array->{api}->{-regexes}}) {
+                $def->{api}->{-regexes}->{$name} = $array->{api}->{-regexes}->{$name};
+            }
+        }
+    }
+
     print_api_string($out, $def->{api}, 'struct', $def->{name});
 
     if (length($def->{description})) {
@@ -217,9 +236,6 @@ my sub print_struct : prototype($$$) {
     print {$out} "pub struct $def->{name} {\n";
     for my $field (sort keys $def->{fields}->%*) {
         my $field_def = $def->{fields}->{$field};
-        if ($field_def->{kind} eq 'array-field') {
-            push @arrays, $field_def;
-        }
 
         my $name = $field_def->{name};
         my $rust_name = $field_def->{rust_name};
@@ -1097,6 +1113,11 @@ my sub string_type : prototype($$$$) {
         # if (my $kind = $fmt->{kind}) {
         #     $api_props->{format_fixme} = '"LIST TYPE"';
         # }
+    } elsif (defined(my $pattern = delete $schema->{pattern})) {
+        # Handle pattern field directly from schema if no format was specified
+        my $re_name = namify_const(${name_hint}, 're');
+        $api_props->{-regexes}->{$re_name} = $pattern;
+        $api_props->{format} = "&ApiStringFormat::Pattern(&$re_name)";
     }
 
     return 'String';
-- 
2.47.3



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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pdm-devel] [PATCH 2/2] pve-api-types: regenerate
  2025-10-01 15:47 [pdm-devel] [PATCH proxmox 0/2] schema2rust: use 'pattern' if specified Hannes Laimer
  2025-10-01 15:47 ` [pdm-devel] [PATCH 1/2] schema2rust: extract pattern validation from nested API schema fields Hannes Laimer
@ 2025-10-01 15:47 ` Hannes Laimer
  1 sibling, 0 replies; 3+ messages in thread
From: Hannes Laimer @ 2025-10-01 15:47 UTC (permalink / raw)
  To: pdm-devel

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 pve-api-types/src/generated/types.rs | 168 +++++++++++++++++++++++++++
 1 file changed, 168 insertions(+)

diff --git a/pve-api-types/src/generated/types.rs b/pve-api-types/src/generated/types.rs
index 2979e708..2da1fd28 100644
--- a/pve-api-types/src/generated/types.rs
+++ b/pve-api-types/src/generated/types.rs
@@ -247,6 +247,7 @@ pub struct ClusterJoinInfo {
 const_regex! {
 
 CLUSTER_JOIN_INFO_NODELIST_NAME_RE = r##"^(?i:[a-z0-9](?i:[a-z0-9\-]*[a-z0-9])?)$"##;
+CLUSTER_JOIN_INFO_NODELIST_PVE_FP_RE = r##"([A-Fa-f0-9]{2}:){31}[A-Fa-f0-9]{2}"##;
 
 }
 
@@ -268,6 +269,7 @@ CLUSTER_JOIN_INFO_NODELIST_NAME_RE = r##"^(?i:[a-z0-9](?i:[a-z0-9\-]*[a-z0-9])?)
             description: "FIXME: Missing description in PVE.",
         },
         pve_fp: {
+            format: &ApiStringFormat::Pattern(&CLUSTER_JOIN_INFO_NODELIST_PVE_FP_RE),
             type: String,
             description: "FIXME: Missing description in PVE.",
         },
@@ -1217,9 +1219,16 @@ pub struct CreateTokenResponseInfo {
     pub privsep: Option<bool>,
 }
 
+const_regex! {
+
+CREATE_VNET_ALIAS_RE = r##"(?^u:(?^i:[\(\)-_.\w\d\s]{0,256}))"##;
+
+}
+
 #[api(
     properties: {
         alias: {
+            format: &ApiStringFormat::Pattern(&CREATE_VNET_ALIAS_RE),
             max_length: 256,
             optional: true,
             type: String,
@@ -2434,6 +2443,12 @@ pub enum LxcConfigCmode {
 serde_plain::derive_display_from_serialize!(LxcConfigCmode);
 serde_plain::derive_fromstr_from_deserialize!(LxcConfigCmode);
 
+const_regex! {
+
+LXC_CONFIG_DEV_MODE_RE = r##"0[0-7]{3}"##;
+
+}
+
 #[api(
     default_key: "path",
     properties: {
@@ -2447,6 +2462,7 @@ serde_plain::derive_fromstr_from_deserialize!(LxcConfigCmode);
             type: Integer,
         },
         mode: {
+            format: &ApiStringFormat::Pattern(&LXC_CONFIG_DEV_MODE_RE),
             optional: true,
             type: String,
         },
@@ -2490,6 +2506,12 @@ pub struct LxcConfigDev {
     pub uid: Option<u64>,
 }
 
+const_regex! {
+
+LXC_CONFIG_FEATURES_MOUNT_RE = r##"(?^u:(?^:[a-zA-Z0-9_; ]+))"##;
+
+}
+
 #[api(
     properties: {
         force_rw_sys: {
@@ -2509,6 +2531,7 @@ pub struct LxcConfigDev {
             optional: true,
         },
         mount: {
+            format: &ApiStringFormat::Pattern(&LXC_CONFIG_FEATURES_MOUNT_RE),
             optional: true,
             type: String,
         },
@@ -2608,6 +2631,7 @@ serde_plain::derive_fromstr_from_deserialize!(LxcConfigLock);
 
 const_regex! {
 
+LXC_CONFIG_MP_MOUNTOPTIONS_RE = r##"(?^u:(?^:(?^:(discard|lazytime|noatime|nodev|noexec|nosuid))(;(?^:(discard|lazytime|noatime|nodev|noexec|nosuid)))*))"##;
 LXC_CONFIG_MP_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
 
 }
@@ -2624,6 +2648,7 @@ LXC_CONFIG_MP_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
             optional: true,
         },
         mountoptions: {
+            format: &ApiStringFormat::Pattern(&LXC_CONFIG_MP_MOUNTOPTIONS_RE),
             optional: true,
             type: String,
         },
@@ -2711,13 +2736,17 @@ pub struct LxcConfigMp {
 
 const_regex! {
 
+LXC_CONFIG_NET_BRIDGE_RE = r##"[-_.\w\d]+"##;
 LXC_CONFIG_NET_HWADDR_RE = r##"^(?i)[a-f0-9][02468ace](?::[a-f0-9]{2}){5}$"##;
+LXC_CONFIG_NET_NAME_RE = r##"[-_.\w\d]+"##;
+LXC_CONFIG_NET_TRUNKS_RE = r##"(?^u:(?^:\d+(?:;\d+)*))"##;
 
 }
 
 #[api(
     properties: {
         bridge: {
+            format: &ApiStringFormat::Pattern(&LXC_CONFIG_NET_BRIDGE_RE),
             optional: true,
             type: String,
         },
@@ -2761,6 +2790,7 @@ LXC_CONFIG_NET_HWADDR_RE = r##"^(?i)[a-f0-9][02468ace](?::[a-f0-9]{2}){5}$"##;
             type: Integer,
         },
         name: {
+            format: &ApiStringFormat::Pattern(&LXC_CONFIG_NET_NAME_RE),
             type: String,
         },
         tag: {
@@ -2770,6 +2800,7 @@ LXC_CONFIG_NET_HWADDR_RE = r##"^(?i)[a-f0-9][02468ace](?::[a-f0-9]{2}){5}$"##;
             type: Integer,
         },
         trunks: {
+            format: &ApiStringFormat::Pattern(&LXC_CONFIG_NET_TRUNKS_RE),
             optional: true,
             type: String,
         },
@@ -2903,6 +2934,7 @@ serde_plain::derive_fromstr_from_deserialize!(LxcConfigOstype);
 
 const_regex! {
 
+LXC_CONFIG_ROOTFS_MOUNTOPTIONS_RE = r##"(?^u:(?^:(?^:(discard|lazytime|noatime|nodev|noexec|nosuid))(;(?^:(discard|lazytime|noatime|nodev|noexec|nosuid)))*))"##;
 LXC_CONFIG_ROOTFS_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
 
 }
@@ -2915,6 +2947,7 @@ LXC_CONFIG_ROOTFS_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
             optional: true,
         },
         mountoptions: {
+            format: &ApiStringFormat::Pattern(&LXC_CONFIG_ROOTFS_MOUNTOPTIONS_RE),
             optional: true,
             type: String,
         },
@@ -4536,12 +4569,19 @@ pub enum NodeSubscriptionInfoStatus {
 serde_plain::derive_display_from_serialize!(NodeSubscriptionInfoStatus);
 serde_plain::derive_fromstr_from_deserialize!(NodeSubscriptionInfoStatus);
 
+const_regex! {
+
+PROXMOX_REMOTE_FINGERPRINT_RE = r##"([A-Fa-f0-9]{2}:){31}[A-Fa-f0-9]{2}"##;
+
+}
+
 #[api(
     properties: {
         apitoken: {
             type: String,
         },
         fingerprint: {
+            format: &ApiStringFormat::Pattern(&PROXMOX_REMOTE_FINGERPRINT_RE),
             optional: true,
             type: String,
         },
@@ -4648,11 +4688,18 @@ pub enum PveQemuSevFmtType {
 serde_plain::derive_display_from_serialize!(PveQemuSevFmtType);
 serde_plain::derive_fromstr_from_deserialize!(PveQemuSevFmtType);
 
+const_regex! {
+
+PVE_QM_BOOT_LEGACY_RE = r##"[acdn]{1,4}"##;
+
+}
+
 #[api(
     default_key: "legacy",
     properties: {
         legacy: {
             default: "cdn",
+            format: &ApiStringFormat::Pattern(&PVE_QM_BOOT_LEGACY_RE),
             optional: true,
             type: String,
         },
@@ -4738,7 +4785,14 @@ pub struct PveQmCicustom {
 
 const_regex! {
 
+PVE_QM_HOSTPCI_DEVICE_ID_RE = r##"(?^u:(?^:^0x[0-9a-fA-F]{4}$))"##;
+PVE_QM_HOSTPCI_HOST_RE = r##"(?^u:(?^:(?^:(?:[a-f0-9]{4,}:)?[a-f0-9]{2}:[a-f0-9]{2}(?:\.[a-f0-9])?)(;(?^:(?:[a-f0-9]{4,}:)?[a-f0-9]{2}:[a-f0-9]{2}(?:\.[a-f0-9])?))*))"##;
 PVE_QM_HOSTPCI_MAPPING_RE = r##"^(?i:[a-z][a-z0-9_-]+)$"##;
+PVE_QM_HOSTPCI_MDEV_RE = r##"[^/\.:]+"##;
+PVE_QM_HOSTPCI_ROMFILE_RE = r##"[^,;]+"##;
+PVE_QM_HOSTPCI_SUB_DEVICE_ID_RE = r##"(?^u:(?^:^0x[0-9a-fA-F]{4}$))"##;
+PVE_QM_HOSTPCI_SUB_VENDOR_ID_RE = r##"(?^u:(?^:^0x[0-9a-fA-F]{4}$))"##;
+PVE_QM_HOSTPCI_VENDOR_ID_RE = r##"(?^u:(?^:^0x[0-9a-fA-F]{4}$))"##;
 
 }
 
@@ -4746,10 +4800,12 @@ PVE_QM_HOSTPCI_MAPPING_RE = r##"^(?i:[a-z][a-z0-9_-]+)$"##;
     default_key: "host",
     properties: {
         "device-id": {
+            format: &ApiStringFormat::Pattern(&PVE_QM_HOSTPCI_DEVICE_ID_RE),
             optional: true,
             type: String,
         },
         host: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_HOSTPCI_HOST_RE),
             optional: true,
             type: String,
         },
@@ -4763,6 +4819,7 @@ PVE_QM_HOSTPCI_MAPPING_RE = r##"^(?i:[a-z][a-z0-9_-]+)$"##;
             type: String,
         },
         mdev: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_HOSTPCI_MDEV_RE),
             optional: true,
             type: String,
         },
@@ -4775,18 +4832,22 @@ PVE_QM_HOSTPCI_MAPPING_RE = r##"^(?i:[a-z][a-z0-9_-]+)$"##;
             optional: true,
         },
         romfile: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_HOSTPCI_ROMFILE_RE),
             optional: true,
             type: String,
         },
         "sub-device-id": {
+            format: &ApiStringFormat::Pattern(&PVE_QM_HOSTPCI_SUB_DEVICE_ID_RE),
             optional: true,
             type: String,
         },
         "sub-vendor-id": {
+            format: &ApiStringFormat::Pattern(&PVE_QM_HOSTPCI_SUB_VENDOR_ID_RE),
             optional: true,
             type: String,
         },
         "vendor-id": {
+            format: &ApiStringFormat::Pattern(&PVE_QM_HOSTPCI_VENDOR_ID_RE),
             optional: true,
             type: String,
         },
@@ -4876,6 +4937,7 @@ const_regex! {
 PVE_QM_IDE_MODEL_RE = r##"^[-%a-zA-Z0-9_.!~*'()]*$"##;
 PVE_QM_IDE_SERIAL_RE = r##"^[-%a-zA-Z0-9_.!~*'()]*$"##;
 PVE_QM_IDE_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
+PVE_QM_IDE_WWN_RE = r##"(?^u:(?^:^(0x)[0-9a-fA-F]{16}))"##;
 
 }
 
@@ -5022,6 +5084,7 @@ PVE_QM_IDE_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
             type: PveQmIdeWerror,
         },
         wwn: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_IDE_WWN_RE),
             optional: true,
             type: String,
         },
@@ -5445,6 +5508,18 @@ pub enum PveQmRngSource {
 serde_plain::derive_display_from_serialize!(PveQmRngSource);
 serde_plain::derive_fromstr_from_deserialize!(PveQmRngSource);
 
+const_regex! {
+
+PVE_QM_SMBIOS1_FAMILY_RE = r##"[A-Za-z0-9+\/]+={0,2}"##;
+PVE_QM_SMBIOS1_MANUFACTURER_RE = r##"[A-Za-z0-9+\/]+={0,2}"##;
+PVE_QM_SMBIOS1_PRODUCT_RE = r##"[A-Za-z0-9+\/]+={0,2}"##;
+PVE_QM_SMBIOS1_SERIAL_RE = r##"[A-Za-z0-9+\/]+={0,2}"##;
+PVE_QM_SMBIOS1_SKU_RE = r##"[A-Za-z0-9+\/]+={0,2}"##;
+PVE_QM_SMBIOS1_UUID_RE = r##"[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}"##;
+PVE_QM_SMBIOS1_VERSION_RE = r##"[A-Za-z0-9+\/]+={0,2}"##;
+
+}
+
 #[api(
     properties: {
         base64: {
@@ -5452,30 +5527,37 @@ serde_plain::derive_fromstr_from_deserialize!(PveQmRngSource);
             optional: true,
         },
         family: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_SMBIOS1_FAMILY_RE),
             optional: true,
             type: String,
         },
         manufacturer: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_SMBIOS1_MANUFACTURER_RE),
             optional: true,
             type: String,
         },
         product: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_SMBIOS1_PRODUCT_RE),
             optional: true,
             type: String,
         },
         serial: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_SMBIOS1_SERIAL_RE),
             optional: true,
             type: String,
         },
         sku: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_SMBIOS1_SKU_RE),
             optional: true,
             type: String,
         },
         uuid: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_SMBIOS1_UUID_RE),
             optional: true,
             type: String,
         },
         version: {
+            format: &ApiStringFormat::Pattern(&PVE_QM_SMBIOS1_VERSION_RE),
             optional: true,
             type: String,
         },
@@ -5583,6 +5665,13 @@ pub enum PveQmWatchdogModel {
 serde_plain::derive_display_from_serialize!(PveQmWatchdogModel);
 serde_plain::derive_fromstr_from_deserialize!(PveQmWatchdogModel);
 
+const_regex! {
+
+PVE_VM_CPU_CONF_FLAGS_RE = r##"(?^u:(?^:(?^:([+-])([a-zA-Z0-9\-_\.]+))(;(?^:([+-])([a-zA-Z0-9\-_\.]+)))*))"##;
+PVE_VM_CPU_CONF_HV_VENDOR_ID_RE = r##"(?^u:(?^:[a-zA-Z0-9]{1,12}))"##;
+
+}
+
 #[api(
     default_key: "cputype",
     properties: {
@@ -5592,6 +5681,7 @@ serde_plain::derive_fromstr_from_deserialize!(PveQmWatchdogModel);
             type: String,
         },
         flags: {
+            format: &ApiStringFormat::Pattern(&PVE_VM_CPU_CONF_FLAGS_RE),
             optional: true,
             type: String,
         },
@@ -5606,6 +5696,7 @@ serde_plain::derive_fromstr_from_deserialize!(PveQmWatchdogModel);
             optional: true,
         },
         "hv-vendor-id": {
+            format: &ApiStringFormat::Pattern(&PVE_VM_CPU_CONF_HV_VENDOR_ID_RE),
             optional: true,
             type: String,
         },
@@ -5895,11 +5986,17 @@ serde_plain::derive_fromstr_from_deserialize!(PveVmCpuConfReportedModel);
 
 const_regex! {
 
+QEMU_CONFIG_PARALLEL_RE = r##"/dev/parport\d+|/dev/usb/lp\d+"##;
+QEMU_CONFIG_SERIAL_RE = r##"(/dev/.+|socket)"##;
 QEMU_CONFIG_AFFINITY_RE = r##"^(\s*\d+(-\d+)?\s*)(,\s*\d+(-\d+)?\s*)?$"##;
 QEMU_CONFIG_BOOTDISK_RE = r##"^(ide|sata|scsi|virtio|efidisk|tpmstate)\d+$"##;
 QEMU_CONFIG_PARENT_RE = r##"^(?i:[a-z][a-z0-9_-]+)$"##;
+QEMU_CONFIG_RUNNING_NETS_HOST_MTU_RE = r##"net\d+=\d+(,net\d+=\d+)*"##;
+QEMU_CONFIG_RUNNINGCPU_RE = r##"(?^u:(?^:^((?>[+-]?[\w\-\._=]+,?)+)$))"##;
 QEMU_CONFIG_SSHKEYS_RE = r##"^[-%a-zA-Z0-9_.!~*'()]*$"##;
+QEMU_CONFIG_STARTDATE_RE = r##"(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)"##;
 QEMU_CONFIG_TAGS_RE = r##"^(?i)[a-z0-9_][a-z0-9_\-+.]*$"##;
+QEMU_CONFIG_VMGENID_RE = r##"(?:[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}|[01])"##;
 QEMU_CONFIG_VMSTATESTORAGE_RE = r##"^(?i:[a-z][a-z0-9\-_.]*[a-z0-9])$"##;
 
 }
@@ -6154,10 +6251,12 @@ QEMU_CONFIG_VMSTATESTORAGE_RE = r##"^(?i:[a-z][a-z0-9\-_.]*[a-z0-9])$"##;
             type: String,
         },
         "running-nets-host-mtu": {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_RUNNING_NETS_HOST_MTU_RE),
             optional: true,
             type: String,
         },
         runningcpu: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_RUNNINGCPU_RE),
             optional: true,
             type: String,
         },
@@ -6225,6 +6324,7 @@ QEMU_CONFIG_VMSTATESTORAGE_RE = r##"^(?i:[a-z][a-z0-9\-_.]*[a-z0-9])$"##;
         },
         startdate: {
             default: "now",
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_STARTDATE_RE),
             optional: true,
             type: String,
             type_text: "(now | YYYY-MM-DD | YYYY-MM-DDTHH:MM:SS)",
@@ -6281,6 +6381,7 @@ QEMU_CONFIG_VMSTATESTORAGE_RE = r##"^(?i:[a-z][a-z0-9\-_.]*[a-z0-9])$"##;
         },
         vmgenid: {
             default: "1 (autogenerated)",
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_VMGENID_RE),
             optional: true,
             type: String,
         },
@@ -6802,6 +6903,7 @@ generate_array_field! {
     r#"Map host parallel devices (n is 0 to 2)."#,
     String => {
         description: "Map host parallel devices (n is 0 to 2).",
+        format: &ApiStringFormat::Pattern(&QEMU_CONFIG_PARALLEL_RE),
         type: String,
     }
     parallel
@@ -6831,6 +6933,7 @@ generate_array_field! {
     r#"Create a serial device inside the VM (n is 0 to 3)"#,
     String => {
         description: "Create a serial device inside the VM (n is 0 to 3)",
+        format: &ApiStringFormat::Pattern(&QEMU_CONFIG_SERIAL_RE),
         type: String,
     }
     serial
@@ -7127,9 +7230,16 @@ pub enum QemuConfigHugepages {
 serde_plain::derive_display_from_serialize!(QemuConfigHugepages);
 serde_plain::derive_fromstr_from_deserialize!(QemuConfigHugepages);
 
+const_regex! {
+
+QEMU_CONFIG_IVSHMEM_NAME_RE = r##"[a-zA-Z0-9\-]+"##;
+
+}
+
 #[api(
     properties: {
         name: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_IVSHMEM_NAME_RE),
             optional: true,
             type: String,
         },
@@ -7271,6 +7381,12 @@ pub enum QemuConfigLock {
 serde_plain::derive_display_from_serialize!(QemuConfigLock);
 serde_plain::derive_fromstr_from_deserialize!(QemuConfigLock);
 
+const_regex! {
+
+QEMU_CONFIG_MACHINE_TYPE_RE = r##"(pc|pc(-i440fx)?-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|q35|pc-q35-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|virt(?:-\d+(\.\d+)+)?(\+pve\d+)?)"##;
+
+}
+
 #[api(
     default_key: "type",
     properties: {
@@ -7288,6 +7404,7 @@ serde_plain::derive_fromstr_from_deserialize!(QemuConfigLock);
             optional: true,
         },
         type: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_MACHINE_TYPE_RE),
             max_length: 40,
             optional: true,
             type: String,
@@ -7364,9 +7481,16 @@ pub struct QemuConfigMemory {
     pub current: u64,
 }
 
+const_regex! {
+
+QEMU_CONFIG_META_CREATION_QEMU_RE = r##"\d+(\.\d+)+"##;
+
+}
+
 #[api(
     properties: {
         "creation-qemu": {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_META_CREATION_QEMU_RE),
             optional: true,
             type: String,
         },
@@ -7395,6 +7519,7 @@ const_regex! {
 
 QEMU_CONFIG_NET_BRIDGE_RE = r##"^[-_.\w\d]+$"##;
 QEMU_CONFIG_NET_MACADDR_RE = r##"^(?i)[a-f0-9][02468ace](?::[a-f0-9]{2}){5}$"##;
+QEMU_CONFIG_NET_TRUNKS_RE = r##"(?^u:(?^:\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*))"##;
 
 }
 
@@ -7465,6 +7590,7 @@ QEMU_CONFIG_NET_MACADDR_RE = r##"^(?i)[a-f0-9][02468ace](?::[a-f0-9]{2}){5}$"##;
             type: Integer,
         },
         trunks: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_NET_TRUNKS_RE),
             optional: true,
             type: String,
         },
@@ -7583,12 +7709,21 @@ pub enum QemuConfigNetModel {
 serde_plain::derive_display_from_serialize!(QemuConfigNetModel);
 serde_plain::derive_fromstr_from_deserialize!(QemuConfigNetModel);
 
+const_regex! {
+
+QEMU_CONFIG_NUMA_CPUS_RE = r##"(?^u:(?^:\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*))"##;
+QEMU_CONFIG_NUMA_HOSTNODES_RE = r##"(?^u:(?^:\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*))"##;
+
+}
+
 #[api(
     properties: {
         cpus: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_NUMA_CPUS_RE),
             type: String,
         },
         hostnodes: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_NUMA_HOSTNODES_RE),
             optional: true,
             type: String,
         },
@@ -7685,6 +7820,7 @@ const_regex! {
 
 QEMU_CONFIG_SATA_SERIAL_RE = r##"^[-%a-zA-Z0-9_.!~*'()]*$"##;
 QEMU_CONFIG_SATA_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
+QEMU_CONFIG_SATA_WWN_RE = r##"(?^u:(?^:^(0x)[0-9a-fA-F]{16}))"##;
 
 }
 
@@ -7825,6 +7961,7 @@ QEMU_CONFIG_SATA_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
             type: PveQmIdeWerror,
         },
         wwn: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_SATA_WWN_RE),
             optional: true,
             type: String,
         },
@@ -8010,8 +8147,11 @@ pub struct QemuConfigSata {
 
 const_regex! {
 
+QEMU_CONFIG_SCSI_PRODUCT_RE = r##"[A-Za-z0-9\-_\s]{,16}"##;
 QEMU_CONFIG_SCSI_SERIAL_RE = r##"^[-%a-zA-Z0-9_.!~*'()]*$"##;
 QEMU_CONFIG_SCSI_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
+QEMU_CONFIG_SCSI_VENDOR_RE = r##"[A-Za-z0-9\-_\s]{,8}"##;
+QEMU_CONFIG_SCSI_WWN_RE = r##"(?^u:(?^:^(0x)[0-9a-fA-F]{16}))"##;
 
 }
 
@@ -8121,6 +8261,7 @@ QEMU_CONFIG_SCSI_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
             type: PveQmIdeMedia,
         },
         product: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_SCSI_PRODUCT_RE),
             optional: true,
             type: String,
         },
@@ -8169,6 +8310,7 @@ QEMU_CONFIG_SCSI_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
             optional: true,
         },
         vendor: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_SCSI_VENDOR_RE),
             optional: true,
             type: String,
         },
@@ -8177,6 +8319,7 @@ QEMU_CONFIG_SCSI_SIZE_RE = r##"^(\d+(\.\d+)?)([KMGT])?$"##;
             type: PveQmIdeWerror,
         },
         wwn: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_SCSI_WWN_RE),
             optional: true,
             type: String,
         },
@@ -8533,6 +8676,7 @@ pub struct QemuConfigUnused {
 
 const_regex! {
 
+QEMU_CONFIG_USB_HOST_RE = r##"(?^u:(?^:(?:(?:(?^:(0x)?([0-9A-Fa-f]{4}):(0x)?([0-9A-Fa-f]{4})))|(?:(?^:(\d+)\-(\d+(\.\d+)*)))|[Ss][Pp][Ii][Cc][Ee])))"##;
 QEMU_CONFIG_USB_MAPPING_RE = r##"^(?i:[a-z][a-z0-9_-]+)$"##;
 
 }
@@ -8541,6 +8685,7 @@ QEMU_CONFIG_USB_MAPPING_RE = r##"^(?i:[a-z][a-z0-9_-]+)$"##;
     default_key: "host",
     properties: {
         host: {
+            format: &ApiStringFormat::Pattern(&QEMU_CONFIG_USB_HOST_RE),
             optional: true,
             type: String,
         },
@@ -10280,9 +10425,16 @@ pub enum SdnObjectState {
 serde_plain::derive_display_from_serialize!(SdnObjectState);
 serde_plain::derive_fromstr_from_deserialize!(SdnObjectState);
 
+const_regex! {
+
+SDN_VNET_ALIAS_RE = r##"(?^u:(?^i:[\(\)-_.\w\d\s]{0,256}))"##;
+
+}
+
 #[api(
     properties: {
         alias: {
+            format: &ApiStringFormat::Pattern(&SDN_VNET_ALIAS_RE),
             max_length: 256,
             optional: true,
             type: String,
@@ -10372,9 +10524,16 @@ pub struct SdnVnet {
     pub zone: Option<String>,
 }
 
+const_regex! {
+
+SDN_VNET_PENDING_ALIAS_RE = r##"(?^u:(?^i:[\(\)-_.\w\d\s]{0,256}))"##;
+
+}
+
 #[api(
     properties: {
         alias: {
+            format: &ApiStringFormat::Pattern(&SDN_VNET_PENDING_ALIAS_RE),
             max_length: 256,
             optional: true,
             type: String,
@@ -11035,6 +11194,7 @@ pub struct StartLxc {
 const_regex! {
 
 START_QEMU_MIGRATEDFROM_RE = r##"^(?i:[a-z0-9](?i:[a-z0-9\-]*[a-z0-9])?)$"##;
+START_QEMU_NETS_HOST_MTU_RE = r##"net\d+=\d+(,net\d+=\d+)*"##;
 
 }
 
@@ -11064,6 +11224,7 @@ START_QEMU_MIGRATEDFROM_RE = r##"^(?i:[a-z0-9](?i:[a-z0-9\-]*[a-z0-9])?)$"##;
             type: StartQemuMigrationType,
         },
         "nets-host-mtu": {
+            format: &ApiStringFormat::Pattern(&START_QEMU_NETS_HOST_MTU_RE),
             optional: true,
             type: String,
         },
@@ -11553,6 +11714,12 @@ pub struct TaskStatus {
     pub user: String,
 }
 
+const_regex! {
+
+VERSION_RESPONSE_REPOID_RE = r##"[0-9a-fA-F]{8,64}"##;
+
+}
+
 #[api(
     properties: {
         console: {
@@ -11563,6 +11730,7 @@ pub struct TaskStatus {
             type: String,
         },
         repoid: {
+            format: &ApiStringFormat::Pattern(&VERSION_RESPONSE_REPOID_RE),
             type: String,
         },
         version: {
-- 
2.47.3



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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-01 15:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-01 15:47 [pdm-devel] [PATCH proxmox 0/2] schema2rust: use 'pattern' if specified Hannes Laimer
2025-10-01 15:47 ` [pdm-devel] [PATCH 1/2] schema2rust: extract pattern validation from nested API schema fields Hannes Laimer
2025-10-01 15:47 ` [pdm-devel] [PATCH 2/2] pve-api-types: regenerate Hannes Laimer

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