From 783cbcb499a50797c1f5b23370bcd6cab9993e84 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 10 Aug 2021 14:17:09 +0200 Subject: [PATCH] fixup schema entry for updaters with explicit types Signed-off-by: Wolfgang Bumiller --- proxmox-api-macro/src/api/structs.rs | 13 +++++++++++-- proxmox-api-macro/tests/updater.rs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/proxmox-api-macro/src/api/structs.rs b/proxmox-api-macro/src/api/structs.rs index d7973518..f761c9be 100644 --- a/proxmox-api-macro/src/api/structs.rs +++ b/proxmox-api-macro/src/api/structs.rs @@ -498,9 +498,8 @@ fn handle_updater_field( } }; - field_schema.optional = field.ty.clone().into(); - let span = Span::call_site(); + field_schema.optional = field.ty.clone().into(); let updater = syn::TypePath { qself: Some(syn::QSelf { lt_token: syn::token::Lt { spans: [span] }, @@ -515,6 +514,16 @@ fn handle_updater_field( &["proxmox", "api", "schema", "Updatable", "Updater"], ), }; + + // we also need to update the schema to point to the updater's schema for `type: Foo` entries + if let SchemaItem::ExternType(path) = &mut field_schema.schema.item { + *path = syn::ExprPath { + attrs: Vec::new(), + qself: updater.qself.clone(), + path: updater.path.clone(), + }; + } + field.ty = syn::Type::Path(updater); if field_schema.flatten_in_struct { diff --git a/proxmox-api-macro/tests/updater.rs b/proxmox-api-macro/tests/updater.rs index 02ade728..df4e5393 100644 --- a/proxmox-api-macro/tests/updater.rs +++ b/proxmox-api-macro/tests/updater.rs @@ -38,7 +38,7 @@ pub struct Complex { }, )] /// One of the baaaad cases. -#[derive(Updater)] +#[derive(Default, Updater)] #[serde(rename_all = "kebab-case")] pub struct SuperComplex { /// An extra field not part of the flattened struct.