Skip to content

Commit 1089c1f

Browse files
committed
fix(ccusage): preserve config schema root shape
Wrap the Rust-generated root schema back under definitions.ccusage-config and keep the top-level shape used by the previous TypeScript generator. This keeps the public schema document layout familiar while preserving the Rust-owned option definitions, including coding-agent defaults and command-specific settings for Codex, OpenCode, Amp, and pi-agent.
1 parent 85a2f61 commit 1089c1f

2 files changed

Lines changed: 125 additions & 75 deletions

File tree

‎apps/ccusage/config-schema.json‎

Lines changed: 78 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2+
"$ref": "#/definitions/ccusage-config",
23
"$schema": "https://json-schema.org/draft-07/schema#",
3-
"additionalProperties": false,
44
"definitions": {
55
"AmpCommandsConfig": {
66
"additionalProperties": false,
@@ -1152,9 +1152,84 @@
11521152
}
11531153
},
11541154
"type": "object"
1155+
},
1156+
"ccusage-config": {
1157+
"additionalProperties": false,
1158+
"description": "Configuration file for ccusage",
1159+
"markdownDescription": "Configuration file for ccusage",
1160+
"properties": {
1161+
"$schema": {
1162+
"description": "JSON Schema URL for validation and autocomplete.",
1163+
"markdownDescription": "JSON Schema URL for validation and autocomplete.",
1164+
"type": "string"
1165+
},
1166+
"amp": {
1167+
"allOf": [
1168+
{
1169+
"$ref": "#/definitions/AmpConfig"
1170+
}
1171+
],
1172+
"description": "Amp configuration.",
1173+
"markdownDescription": "Amp configuration."
1174+
},
1175+
"claude": {
1176+
"allOf": [
1177+
{
1178+
"$ref": "#/definitions/ClaudeConfig"
1179+
}
1180+
],
1181+
"description": "Claude Code configuration.",
1182+
"markdownDescription": "Claude Code configuration."
1183+
},
1184+
"codex": {
1185+
"allOf": [
1186+
{
1187+
"$ref": "#/definitions/CodexConfig"
1188+
}
1189+
],
1190+
"description": "Codex configuration.",
1191+
"markdownDescription": "Codex configuration."
1192+
},
1193+
"commands": {
1194+
"allOf": [
1195+
{
1196+
"$ref": "#/definitions/RootCommandsConfig"
1197+
}
1198+
],
1199+
"description": "Command-specific configuration for all-agent reports.",
1200+
"markdownDescription": "Command-specific configuration for all-agent reports."
1201+
},
1202+
"defaults": {
1203+
"allOf": [
1204+
{
1205+
"$ref": "#/definitions/SharedOptions"
1206+
}
1207+
],
1208+
"description": "Default values for all-agent reports and legacy Claude commands.",
1209+
"markdownDescription": "Default values for all-agent reports and legacy Claude commands."
1210+
},
1211+
"opencode": {
1212+
"allOf": [
1213+
{
1214+
"$ref": "#/definitions/OpenCodeConfig"
1215+
}
1216+
],
1217+
"description": "OpenCode configuration.",
1218+
"markdownDescription": "OpenCode configuration."
1219+
},
1220+
"pi": {
1221+
"allOf": [
1222+
{
1223+
"$ref": "#/definitions/PiConfig"
1224+
}
1225+
],
1226+
"description": "pi-agent configuration.",
1227+
"markdownDescription": "pi-agent configuration."
1228+
}
1229+
},
1230+
"type": "object"
11551231
}
11561232
},
1157-
"description": "Configuration file for ccusage",
11581233
"examples": [
11591234
{
11601235
"$schema": "https://ccusage.com/config-schema.json",
@@ -1182,77 +1257,5 @@
11821257
}
11831258
}
11841259
],
1185-
"markdownDescription": "Configuration file for ccusage",
1186-
"properties": {
1187-
"$schema": {
1188-
"description": "JSON Schema URL for validation and autocomplete.",
1189-
"markdownDescription": "JSON Schema URL for validation and autocomplete.",
1190-
"type": "string"
1191-
},
1192-
"amp": {
1193-
"allOf": [
1194-
{
1195-
"$ref": "#/definitions/AmpConfig"
1196-
}
1197-
],
1198-
"description": "Amp configuration.",
1199-
"markdownDescription": "Amp configuration."
1200-
},
1201-
"claude": {
1202-
"allOf": [
1203-
{
1204-
"$ref": "#/definitions/ClaudeConfig"
1205-
}
1206-
],
1207-
"description": "Claude Code configuration.",
1208-
"markdownDescription": "Claude Code configuration."
1209-
},
1210-
"codex": {
1211-
"allOf": [
1212-
{
1213-
"$ref": "#/definitions/CodexConfig"
1214-
}
1215-
],
1216-
"description": "Codex configuration.",
1217-
"markdownDescription": "Codex configuration."
1218-
},
1219-
"commands": {
1220-
"allOf": [
1221-
{
1222-
"$ref": "#/definitions/RootCommandsConfig"
1223-
}
1224-
],
1225-
"description": "Command-specific configuration for all-agent reports.",
1226-
"markdownDescription": "Command-specific configuration for all-agent reports."
1227-
},
1228-
"defaults": {
1229-
"allOf": [
1230-
{
1231-
"$ref": "#/definitions/SharedOptions"
1232-
}
1233-
],
1234-
"description": "Default values for all-agent reports and legacy Claude commands.",
1235-
"markdownDescription": "Default values for all-agent reports and legacy Claude commands."
1236-
},
1237-
"opencode": {
1238-
"allOf": [
1239-
{
1240-
"$ref": "#/definitions/OpenCodeConfig"
1241-
}
1242-
],
1243-
"description": "OpenCode configuration.",
1244-
"markdownDescription": "OpenCode configuration."
1245-
},
1246-
"pi": {
1247-
"allOf": [
1248-
{
1249-
"$ref": "#/definitions/PiConfig"
1250-
}
1251-
],
1252-
"description": "pi-agent configuration.",
1253-
"markdownDescription": "pi-agent configuration."
1254-
}
1255-
},
1256-
"title": "ccusage Configuration",
1257-
"type": "object"
1260+
"title": "ccusage Configuration"
12581261
}

‎rust/crates/ccusage/src/config_schema.rs‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ pub(crate) fn generate_config_schema_json() -> String {
472472
}
473473
enrich_schema(&mut schema);
474474
add_schema_defaults(&mut schema);
475+
wrap_root_schema(&mut schema);
475476
let mut json = tab_indent_json(&serde_json::to_string_pretty(&schema).unwrap());
476477
json.push('\n');
477478
json
@@ -606,6 +607,37 @@ fn set_definition_defaults(schema: &mut Value, definition: &str, defaults: &[(&s
606607
}
607608
}
608609

610+
fn wrap_root_schema(schema: &mut Value) {
611+
let Value::Object(root) = schema else {
612+
return;
613+
};
614+
let mut definitions = root
615+
.remove("definitions")
616+
.and_then(|definitions| match definitions {
617+
Value::Object(definitions) => Some(definitions),
618+
_ => None,
619+
})
620+
.unwrap_or_default();
621+
let mut root_definition = Map::new();
622+
for key in [
623+
"additionalProperties",
624+
"description",
625+
"markdownDescription",
626+
"properties",
627+
"type",
628+
] {
629+
if let Some(value) = root.remove(key) {
630+
root_definition.insert(key.to_string(), value);
631+
}
632+
}
633+
definitions.insert("ccusage-config".to_string(), Value::Object(root_definition));
634+
root.insert(
635+
"$ref".to_string(),
636+
Value::String("#/definitions/ccusage-config".to_string()),
637+
);
638+
root.insert("definitions".to_string(), Value::Object(definitions));
639+
}
640+
609641
#[cfg(test)]
610642
mod tests {
611643
use std::collections::BTreeSet;
@@ -707,6 +739,21 @@ mod tests {
707739
assert!(!contains_key(&value, "anyOf"));
708740
}
709741

742+
#[test]
743+
fn generated_schema_keeps_legacy_root_definition_shape() {
744+
let schema = generated_schema();
745+
746+
assert_eq!(
747+
schema["$ref"].as_str(),
748+
Some("#/definitions/ccusage-config")
749+
);
750+
assert_properties(
751+
&schema,
752+
"ccusage-config",
753+
&["$schema", "amp", "claude", "codex", "commands", "defaults", "opencode", "pi"],
754+
);
755+
}
756+
710757
#[test]
711758
fn schema_allows_cli_config_file_shape() {
712759
let schema = generated_schema();

0 commit comments

Comments
 (0)