Skip to content

Commit

Permalink
feat(cli): generate json schemas locally
Browse files Browse the repository at this point in the history
This commit updates the various komorebic json schema generation
commands to generate the schemas locally, without requiring a running
instance of komorebi to communicate with over IPC.
  • Loading branch information
LGUG2Z committed Sep 18, 2024
1 parent 96d094d commit df19d06
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 36 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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\
1 change: 1 addition & 0 deletions komorebi-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions komorebic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
27 changes: 23 additions & 4 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2539,16 +2543,31 @@ Stop-Process -Name:komorebi -ErrorAction SilentlyContinue
);
}
SubCommand::ApplicationSpecificConfigurationSchema => {
print_query(&SocketMessage::ApplicationSpecificConfigurationSchema);
let asc = schema_for!(Vec<ApplicationConfiguration>);
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(&notification)?;
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::<StaticConfig>();
let schema = serde_json::to_string_pretty(&socket_message)?;
println!("{schema}");
}
SubCommand::GenerateStaticConfig => {
print_query(&SocketMessage::GenerateStaticConfig);
Expand Down
50 changes: 18 additions & 32 deletions schema.asc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"null"
],
"items": {
"$ref": "#/definitions/IdWithIdentifierAndComment"
"$ref": "#/definitions/MatchingRule"
}
},
"identifier": {
Expand Down Expand Up @@ -53,9 +53,9 @@
"enum": [
"object_name_change",
"layered",
"border_overflow",
"tray_and_multi_window",
"force"
"force",
"border_overflow"
]
},
"IdWithIdentifier": {
Expand Down Expand Up @@ -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",
Expand All @@ -122,7 +104,11 @@
"StartsWith",
"EndsWith",
"Contains",
"Regex"
"Regex",
"DoesNotEndWith",
"DoesNotStartWith",
"DoesNotEqual",
"DoesNotContain"
]
}
}
Expand Down

0 comments on commit df19d06

Please sign in to comment.