fix(build): move capability schema definitions to root (#8906)

This commit is contained in:
Lucas Fernandes Nogueira 2024-02-19 14:46:21 -03:00 committed by GitHub
parent 6f064a0d6f
commit 0e8e9cd064
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-build": patch:bug
---
Fixes the capability schema not resolving inner definitions.

View File

@ -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") { if let Some(Schema::Object(obj)) = schema.definitions.get_mut("PermissionEntry") {
let permission_entry_any_of_schemas = obj.subschemas().any_of.as_mut().unwrap(); let permission_entry_any_of_schemas = obj.subschemas().any_of.as_mut().unwrap();
@ -96,17 +98,20 @@ fn capabilities_schema(plugin_manifests: &BTreeMap<String, Manifest>) -> RootSch
for (plugin, manifest) in plugin_manifests { for (plugin, manifest) in plugin_manifests {
if let Some(global_scope_schema) = &manifest.global_scope_schema { if let Some(global_scope_schema) = &manifest.global_scope_schema {
let global_scope_schema_def: Schema = serde_json::from_value(global_scope_schema.clone()) let global_scope_schema_def: RootSchema =
.unwrap_or_else(|e| panic!("invalid JSON schema for plugin {plugin}: {e}")); 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 { let global_scope_schema = Schema::Object(SchemaObject {
array: Some(Box::new(ArrayValidation { 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()
})), })),
..Default::default() ..Default::default()
}); });
definitions.push(global_scope_schema_def.definitions);
let mut required = BTreeSet::new(); let mut required = BTreeSet::new();
required.insert("identifier".to_string()); required.insert("identifier".to_string());
@ -170,6 +175,10 @@ fn capabilities_schema(plugin_manifests: &BTreeMap<String, Manifest>) -> RootSch
} }
} }
for definitions_map in definitions {
schema.definitions.extend(definitions_map);
}
schema schema
} }