[pbs-devel] [PATCH proxmox 07/18] api-macro: forbid flattened fields
Wolfgang Bumiller
w.bumiller at proxmox.com
Fri Dec 18 12:25:55 CET 2020
They don't appear in the json data structure and therefore
should not be named separately in the schema. Structs with
flattened fields will become an `AllOf` schema instead.
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
proxmox-api-macro/src/api/structs.rs | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/proxmox-api-macro/src/api/structs.rs b/proxmox-api-macro/src/api/structs.rs
index 71cdc8a..a101308 100644
--- a/proxmox-api-macro/src/api/structs.rs
+++ b/proxmox-api-macro/src/api/structs.rs
@@ -162,8 +162,20 @@ fn handle_regular_struct(attribs: JSONObject, stru: syn::ItemStruct) -> Result<T
}
};
+ if attrs.flatten {
+ if let Some(field) = schema_fields.remove(&name) {
+ error!(
+ field.0.span(),
+ "flattened field should not appear in schema, \
+ its name does not appear in serialized data",
+ );
+ }
+ }
+
match schema_fields.remove(&name) {
- Some(field_def) => handle_regular_field(field_def, field, false)?,
+ Some(field_def) => {
+ handle_regular_field(field_def, field, false)?;
+ }
None => {
let mut field_def = (
FieldName::new(name.clone(), span),
--
2.20.1
More information about the pbs-devel
mailing list