diff --git a/Cargo.lock b/Cargo.lock index 496e75604..d14efae16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2766,6 +2766,7 @@ dependencies = [ "paste", "powershell_script", "reqwest", + "schemars", "serde", "serde_json_lenient", "serde_yaml 0.9.34+deprecated", diff --git a/justfile b/justfile index d077616f8..664e52b3f 100644 --- a/justfile +++ b/justfile @@ -45,4 +45,6 @@ docgen: schemagen: komorebic static-config-schema > schema.json + komorebic application-specific-configuration-schema > schema.asc.json + komorebi-bar --schema > schema.bar.json generate-schema-doc .\schema.json --config template_name=js_offline --config minify=false .\static-config-docs\ diff --git a/komorebi-client/src/lib.rs b/komorebi-client/src/lib.rs index f84d2ce5e..4344266ee 100644 --- a/komorebi-client/src/lib.rs +++ b/komorebi-client/src/lib.rs @@ -3,6 +3,7 @@ pub use komorebi::colour::Colour; pub use komorebi::colour::Rgb; +pub use komorebi::config_generation::ApplicationConfiguration; pub use komorebi::container::Container; pub use komorebi::core::config_generation::ApplicationConfigurationGenerator; pub use komorebi::core::resolve_home_path; diff --git a/komorebic/Cargo.toml b/komorebic/Cargo.toml index 6130e2623..073f9b01d 100644 --- a/komorebic/Cargo.toml +++ b/komorebic/Cargo.toml @@ -34,6 +34,7 @@ which = "6" win32-display-data = { workspace = true } windows = { workspace = true } shadow-rs = { workspace = true } +schemars = { workspace = true } [build-dependencies] reqwest = { version = "0.12", features = ["blocking"] } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 9a29ae6a5..7fc030b50 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -25,12 +25,16 @@ use fs_tail::TailedFile; use komorebi_client::resolve_home_path; use komorebi_client::send_message; use komorebi_client::send_query; +use komorebi_client::ApplicationConfiguration; +use komorebi_client::Notification; use lazy_static::lazy_static; use miette::NamedSource; use miette::Report; use miette::SourceOffset; use miette::SourceSpan; use paste::paste; +use schemars::gen::SchemaSettings; +use schemars::schema_for; use which::which; use windows::Win32::Foundation::HWND; use windows::Win32::UI::WindowsAndMessaging::ShowWindow; @@ -2539,16 +2543,31 @@ Stop-Process -Name:komorebi -ErrorAction SilentlyContinue ); } SubCommand::ApplicationSpecificConfigurationSchema => { - print_query(&SocketMessage::ApplicationSpecificConfigurationSchema); + let asc = schema_for!(Vec); + let schema = serde_json::to_string_pretty(&asc)?; + println!("{schema}"); } SubCommand::NotificationSchema => { - print_query(&SocketMessage::NotificationSchema); + let notification = schema_for!(Notification); + let schema = serde_json::to_string_pretty(¬ification)?; + println!("{schema}"); } SubCommand::SocketSchema => { - print_query(&SocketMessage::SocketSchema); + let socket_message = schema_for!(SocketMessage); + let schema = serde_json::to_string_pretty(&socket_message)?; + println!("{schema}"); } SubCommand::StaticConfigSchema => { - print_query(&SocketMessage::StaticConfigSchema); + let settings = SchemaSettings::default().with(|s| { + s.option_nullable = false; + s.option_add_null_type = false; + s.inline_subschemas = true; + }); + + let gen = settings.into_generator(); + let socket_message = gen.into_root_schema_for::(); + let schema = serde_json::to_string_pretty(&socket_message)?; + println!("{schema}"); } SubCommand::GenerateStaticConfig => { print_query(&SocketMessage::GenerateStaticConfig); diff --git a/schema.asc.json b/schema.asc.json index 8a2e4fa27..fb5f20120 100644 --- a/schema.asc.json +++ b/schema.asc.json @@ -19,7 +19,7 @@ "null" ], "items": { - "$ref": "#/definitions/IdWithIdentifierAndComment" + "$ref": "#/definitions/MatchingRule" } }, "identifier": { @@ -53,9 +53,9 @@ "enum": [ "object_name_change", "layered", - "border_overflow", "tray_and_multi_window", - "force" + "force", + "border_overflow" ] }, "IdWithIdentifier": { @@ -83,36 +83,18 @@ } } }, - "IdWithIdentifierAndComment": { - "type": "object", - "required": [ - "id", - "kind" - ], - "properties": { - "comment": { - "type": [ - "string", - "null" - ] - }, - "id": { - "type": "string" - }, - "kind": { - "$ref": "#/definitions/ApplicationIdentifier" + "MatchingRule": { + "anyOf": [ + { + "$ref": "#/definitions/IdWithIdentifier" }, - "matching_strategy": { - "anyOf": [ - { - "$ref": "#/definitions/MatchingStrategy" - }, - { - "type": "null" - } - ] + { + "type": "array", + "items": { + "$ref": "#/definitions/IdWithIdentifier" + } } - } + ] }, "MatchingStrategy": { "type": "string", @@ -122,7 +104,11 @@ "StartsWith", "EndsWith", "Contains", - "Regex" + "Regex", + "DoesNotEndWith", + "DoesNotStartWith", + "DoesNotEqual", + "DoesNotContain" ] } }