From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id D50F51FF179 for ; Wed, 12 Nov 2025 11:23:39 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id F3E031DBA6; Wed, 12 Nov 2025 11:24:22 +0100 (CET) From: Shannon Sterz To: pdm-devel@lists.proxmox.com Date: Wed, 12 Nov 2025 11:24:12 +0100 Message-ID: <20251112102415.175358-6-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251112102415.175358-1-s.sterz@proxmox.com> References: <20251112102415.175358-1-s.sterz@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762943032642 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.061 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox 4/4] docgen: add a stop-gap fix to allow generating schema for pve-api-types X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" Signed-off-by: Shannon Sterz --- proxmox-docgen/src/lib.rs | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/proxmox-docgen/src/lib.rs b/proxmox-docgen/src/lib.rs index 67d502d5..f3d53519 100644 --- a/proxmox-docgen/src/lib.rs +++ b/proxmox-docgen/src/lib.rs @@ -97,7 +97,7 @@ fn dump_schema(schema: &Schema) -> Value { } } Schema::Object(object_schema) => { - data = dump_property_schema(object_schema); + data = dump_property_schema(object_schema, false); data["type"] = "object".into(); if let Some(default_key) = object_schema.default_key { data["default_key"] = default_key.into(); @@ -117,7 +117,12 @@ fn dump_schema(schema: &Schema) -> Value { } } Schema::AllOf(alloff_schema) => { - data = dump_property_schema(alloff_schema); + let dirty_allof = alloff_schema + .list + .iter() + .any(|schema| schema.any_object().is_none()); + + data = dump_property_schema(alloff_schema, dirty_allof); data["type"] = "object".into(); } Schema::OneOf(schema) => { @@ -144,7 +149,8 @@ fn dump_schema(schema: &Schema) -> Value { data } -fn dump_property_schema(param: &dyn ObjectSchemaType) -> Value { +// TODO: remove `dirty_allof` again once pve-api-types generates proper `AllOf` schema. +fn dump_property_schema(param: &dyn ObjectSchemaType, dirty_allof: bool) -> Value { let mut properties = json!({}); for (prop, optional, schema) in param.properties() { @@ -155,13 +161,23 @@ fn dump_property_schema(param: &dyn ObjectSchemaType) -> Value { properties[prop] = property; } - let data = json!({ - "description": param.description(), - "additionalProperties": param.additional_properties(), - "properties": properties, - }); - - data + if dirty_allof { + json!({ + "description": param.description(), + // stop gap for now. pve-api-types generates certain properties as string schema that + // are really property strings (which wrap an object schema anyway). however, + // `additional_properties()` panics there, because it will expect *only* object + // schema. + "additionalProperties": true, + "properties": properties, + }) + } else { + json!({ + "description": param.description(), + "additionalProperties": param.additional_properties(), + "properties": properties, + }) + } } fn dump_api_permission(permission: &Permission, privileges: &[(&str, u64)]) -> Value { @@ -222,7 +238,7 @@ fn dump_api_method_schema( "description": api_method.parameters.description(), }); - data["parameters"] = dump_property_schema(&api_method.parameters); + data["parameters"] = dump_property_schema(&api_method.parameters, false); let mut returns = dump_schema(api_method.returns.schema); if api_method.returns.optional { -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel