From 0e8e9cd064627e734adf8f62e571dc5f4e8f4d9f Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 19 Feb 2024 14:46:21 -0300 Subject: [PATCH] fix(build): move capability schema definitions to root (#8906) --- .changes/fix-capability-schema-definitions.md | 5 +++++ core/tauri-build/src/acl.rs | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .changes/fix-capability-schema-definitions.md diff --git a/.changes/fix-capability-schema-definitions.md b/.changes/fix-capability-schema-definitions.md new file mode 100644 index 000000000..2935b5039 --- /dev/null +++ b/.changes/fix-capability-schema-definitions.md @@ -0,0 +1,5 @@ +--- +"tauri-build": patch:bug +--- + +Fixes the capability schema not resolving inner definitions. diff --git a/core/tauri-build/src/acl.rs b/core/tauri-build/src/acl.rs index c897c86f3..e07841d10 100644 --- a/core/tauri-build/src/acl.rs +++ b/core/tauri-build/src/acl.rs @@ -86,6 +86,8 @@ fn capabilities_schema(plugin_manifests: &BTreeMap) -> RootSch })); } + let mut definitions = Vec::new(); + if let Some(Schema::Object(obj)) = schema.definitions.get_mut("PermissionEntry") { let permission_entry_any_of_schemas = obj.subschemas().any_of.as_mut().unwrap(); @@ -96,17 +98,20 @@ fn capabilities_schema(plugin_manifests: &BTreeMap) -> RootSch for (plugin, manifest) in plugin_manifests { if let Some(global_scope_schema) = &manifest.global_scope_schema { - let global_scope_schema_def: Schema = serde_json::from_value(global_scope_schema.clone()) - .unwrap_or_else(|e| panic!("invalid JSON schema for plugin {plugin}: {e}")); + let global_scope_schema_def: RootSchema = + serde_json::from_value(global_scope_schema.clone()) + .unwrap_or_else(|e| panic!("invalid JSON schema for plugin {plugin}: {e}")); let global_scope_schema = Schema::Object(SchemaObject { array: Some(Box::new(ArrayValidation { - items: Some(global_scope_schema_def.into()), + items: Some(Schema::Object(global_scope_schema_def.schema).into()), ..Default::default() })), ..Default::default() }); + definitions.push(global_scope_schema_def.definitions); + let mut required = BTreeSet::new(); required.insert("identifier".to_string()); @@ -170,6 +175,10 @@ fn capabilities_schema(plugin_manifests: &BTreeMap) -> RootSch } } + for definitions_map in definitions { + schema.definitions.extend(definitions_map); + } + schema }