Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent-client-protocol-schema/src/v2/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,7 @@ pub struct SessionInfo {
/// by the Agent. Omitted, `null`, and empty values are equivalent: the response
/// reports no additional roots.
#[serde_as(deserialize_as = "DefaultOnNull")]
#[cfg_attr(feature = "schemars", schemars(extend("x-deserialize-default-on-null" = true)))]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub additional_directories: Vec<AbsolutePath>,

Expand Down
30 changes: 30 additions & 0 deletions schema-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ mod schema_annotation_tests {

const DEFAULT_ON_ERROR_EXTENSION: &str = "x-deserialize-default-on-error";
const SKIP_INVALID_ITEMS_EXTENSION: &str = "x-deserialize-skip-invalid-items";
const DEFAULT_ON_NULL_EXTENSION: &str = "x-deserialize-default-on-null";

#[test]
fn generated_notice_schema_is_available_without_unstable_features() {
Expand Down Expand Up @@ -970,6 +971,35 @@ mod schema_annotation_tests {
}
}

#[test]
fn source_default_on_null_fields_are_schema_annotated() {
let root = schema_crate_dir();
for module_dir in ["src/v1", "src/v2"] {
for entry in fs::read_dir(root.join(module_dir)).unwrap() {
let path = entry.unwrap().path();
if path.extension().and_then(|ext| ext.to_str()) != Some("rs") {
continue;
}

let source = fs::read_to_string(&path).unwrap();
let lines: Vec<_> = source.lines().collect();
for (line_index, line) in lines.iter().enumerate() {
if !line.contains(r#"#[serde_as(deserialize_as = "DefaultOnNull"#) {
continue;
}

let annotation = lines.get(line_index + 1).copied().unwrap_or_default();
assert!(
annotation.contains(r#""x-deserialize-default-on-null" = true"#),
"{}:{} missing {DEFAULT_ON_NULL_EXTENSION}",
path.display(),
line_index + 1
);
}
}
}
}

#[test]
fn source_meta_fields_are_default_on_error_annotated() {
let root = schema_crate_dir();
Expand Down
3 changes: 2 additions & 1 deletion schema/v2/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4177,7 +4177,8 @@
"type": "array",
"items": {
"$ref": "#/$defs/AbsolutePath"
}
},
"x-deserialize-default-on-null": true
},
"title": {
"description": "Human-readable title for the session\n\nOmitted and `null` are equivalent and mean no title is provided.",
Expand Down
3 changes: 2 additions & 1 deletion schema/v2/schema.unstable.json
Original file line number Diff line number Diff line change
Expand Up @@ -4619,7 +4619,8 @@
"type": "array",
"items": {
"$ref": "#/$defs/AbsolutePath"
}
},
"x-deserialize-default-on-null": true
},
"title": {
"description": "Human-readable title for the session\n\nOmitted and `null` are equivalent and mean no title is provided.",
Expand Down
Loading