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; 6+ 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] 6+ 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-15 12:32   ` Wolfgang Bumiller
  2025-10-01 15:47 ` [pdm-devel] [PATCH 2/2] pve-api-types: regenerate Hannes Laimer
  1 sibling, 1 reply; 6+ 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] 6+ 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; 6+ 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] 6+ messages in thread

* Re: [pdm-devel] [PATCH 1/2] schema2rust: extract pattern validation from nested API schema fields
  2025-10-01 15:47 ` [pdm-devel] [PATCH 1/2] schema2rust: extract pattern validation from nested API schema fields Hannes Laimer
@ 2025-10-15 12:32   ` Wolfgang Bumiller
  2025-10-16  6:13     ` Hannes Laimer
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Bumiller @ 2025-10-15 12:32 UTC (permalink / raw)
  To: Hannes Laimer; +Cc: pdm-devel

The patch itself works, but there are 2 issues:

The currently generated regexes (luckily?) all produce regexes which are
1. anchored
2. compatible with the regex crate

With your patch, a lot of them will not satisfy both.

For 1:
The PVE schema code generally anchors the regexes at *use* time, which
is less than ideal and we could probably move towards including the
anchors in the regexes itself (unless we specifically need them
unanchored for some reason?)
In the rust code we could not do this. The regex crate does not expose
this and requires them to be anchored explicitly within the regex.

We could also include `^` and `$` in the generator, but it'll be a bit
redundant (but won't hurt).

But for 2:
I'm afraid what we need to do is find a way to "whitelist" which regexes
get generated. We could produce TODO comments for the rest.

I went ahead and pushed a commit which produces tests for the regexes.
If you go ahead and run `cargo` test after regenerating with this patch,
you'll see the issue.

On Wed, Oct 01, 2025 at 05:47:16PM +0200, Hannes Laimer wrote:
> 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
> 
> 


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


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

* Re: [pdm-devel] [PATCH 1/2] schema2rust: extract pattern validation from nested API schema fields
  2025-10-15 12:32   ` Wolfgang Bumiller
@ 2025-10-16  6:13     ` Hannes Laimer
  2025-10-16  9:31       ` Wolfgang Bumiller
  0 siblings, 1 reply; 6+ messages in thread
From: Hannes Laimer @ 2025-10-16  6:13 UTC (permalink / raw)
  To: Wolfgang Bumiller; +Cc: pdm-devel

On 10/15/25 14:32, Wolfgang Bumiller wrote:
> The patch itself works, but there are 2 issues:
> 
> The currently generated regexes (luckily?) all produce regexes which are
> 1. anchored
> 2. compatible with the regex crate
> 
> With your patch, a lot of them will not satisfy both.
> 
> For 1:
> The PVE schema code generally anchors the regexes at *use* time, which
> is less than ideal and we could probably move towards including the
> anchors in the regexes itself (unless we specifically need them
> unanchored for some reason?)
> In the rust code we could not do this. The regex crate does not expose
> this and requires them to be anchored explicitly within the regex.
> 
> We could also include `^` and `$` in the generator, but it'll be a bit
> redundant (but won't hurt).
> 
> But for 2:
> I'm afraid what we need to do is find a way to "whitelist" which regexes
> get generated. We could produce TODO comments for the rest.
> 
> I went ahead and pushed a commit which produces tests for the regexes.
> If you go ahead and run `cargo` test after regenerating with this patch,
> you'll see the issue.
> 

Thanks for taking a look! Hmm, I don't think we have patterns that rely
on PCRE specific features, i.e. we could maybe convert those without
losing semantic meaning for validation.

I'm not super familiar with PCRE and its intricacies, but I don't think
we have pattern that couldn't be represented otherwise.

Some things conversion would have to do:
- {,N} -> {0,N}
- in rust we shouldn't need flag-resets, (I think)
- (?^i:...) -> (?i:...)
- ...

Not sure if it would be feasible to try to integrate some kind of
"conversion" into the generator itself. Of the patterns used in the PVE
API spec, I think this would mostly be syntactic things. BUT I did
probably miss some things :P also, is there a reason we would not want
this assuming converting patterns "on-the-fly" in the generator is
feasible?


> On Wed, Oct 01, 2025 at 05:47:16PM +0200, Hannes Laimer wrote:
>> 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
>>
>>



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


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

* Re: [pdm-devel] [PATCH 1/2] schema2rust: extract pattern validation from nested API schema fields
  2025-10-16  6:13     ` Hannes Laimer
@ 2025-10-16  9:31       ` Wolfgang Bumiller
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Bumiller @ 2025-10-16  9:31 UTC (permalink / raw)
  To: Hannes Laimer; +Cc: pdm-devel

On Thu, Oct 16, 2025 at 08:13:14AM +0200, Hannes Laimer wrote:
> On 10/15/25 14:32, Wolfgang Bumiller wrote:
> > The patch itself works, but there are 2 issues:
> > 
> > The currently generated regexes (luckily?) all produce regexes which are
> > 1. anchored
> > 2. compatible with the regex crate
> > 
> > With your patch, a lot of them will not satisfy both.
> > 
> > For 1:
> > The PVE schema code generally anchors the regexes at *use* time, which
> > is less than ideal and we could probably move towards including the
> > anchors in the regexes itself (unless we specifically need them
> > unanchored for some reason?)
> > In the rust code we could not do this. The regex crate does not expose
> > this and requires them to be anchored explicitly within the regex.
> > 
> > We could also include `^` and `$` in the generator, but it'll be a bit
> > redundant (but won't hurt).
> > 
> > But for 2:
> > I'm afraid what we need to do is find a way to "whitelist" which regexes
> > get generated. We could produce TODO comments for the rest.
> > 
> > I went ahead and pushed a commit which produces tests for the regexes.
> > If you go ahead and run `cargo` test after regenerating with this patch,
> > you'll see the issue.
> > 
> 
> Thanks for taking a look! Hmm, I don't think we have patterns that rely
> on PCRE specific features, i.e. we could maybe convert those without
> losing semantic meaning for validation.
> 
> I'm not super familiar with PCRE and its intricacies, but I don't think
> we have pattern that couldn't be represented otherwise.
> 
> Some things conversion would have to do:
> - {,N} -> {0,N}

Weirdly it accepts {N,}, but not {,N} ...

> - in rust we shouldn't need flag-resets, (I think)
> - (?^i:...) -> (?i:...)

Missing a `-` here - (?^i:...) would be (?-i:...) AFAICT ;-)

We'd only not need the *outer* ones, but anything interpolated into the
middle of a regex may well need it.

`qr/foo${other_re}bar/i` <- there's an `/i` at the end, if `$other_re`
uses `qr//` as well, *its* `(?^i:...)` is still required.

Also - we still do need to anchor the un-anchored regexes with `^…$`.

> - ...
> 
> Not sure if it would be feasible to try to integrate some kind of
> "conversion" into the generator itself. Of the patterns used in the PVE
> API spec, I think this would mostly be syntactic things. BUT I did
> probably miss some things :P also, is there a reason we would not want
> this assuming converting patterns "on-the-fly" in the generator is
> feasible?

If the conversion is sound, we can do this. But if that entails
fully and properly parsing regular expressions, then I'd rather manually
vet the regexes and require them to be predefined in generate.pl (with a
from->to mapping to verify that the perl-side hasn't changed)...


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

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

end of thread, other threads:[~2025-10-16  9:32 UTC | newest]

Thread overview: 6+ 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-15 12:32   ` Wolfgang Bumiller
2025-10-16  6:13     ` Hannes Laimer
2025-10-16  9:31       ` Wolfgang Bumiller
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