Skip to content

Commit

Permalink
fix(build): move capability schema definitions to root (#8906)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 19, 2024
1 parent 6f064a0 commit 0e8e9cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-capability-schema-definitions.md
@@ -0,0 +1,5 @@
---
"tauri-build": patch:bug
---

Fixes the capability schema not resolving inner definitions.
15 changes: 12 additions & 3 deletions core/tauri-build/src/acl.rs
Expand Up @@ -86,6 +86,8 @@ fn capabilities_schema(plugin_manifests: &BTreeMap<String, Manifest>) -> 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();

Expand All @@ -96,17 +98,20 @@ fn capabilities_schema(plugin_manifests: &BTreeMap<String, Manifest>) -> 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());

Expand Down Expand Up @@ -170,6 +175,10 @@ fn capabilities_schema(plugin_manifests: &BTreeMap<String, Manifest>) -> RootSch
}
}

for definitions_map in definitions {
schema.definitions.extend(definitions_map);
}

schema
}

Expand Down

0 comments on commit 0e8e9cd

Please sign in to comment.