Skip to content
Closed
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
32 changes: 31 additions & 1 deletion src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,13 @@ fn check_annotations(value: &Value, file: &Path, path: &str, diagnostics: &mut V
}
}

// Recurse
// Recurse into child schemas, but not into keywords that hold JSON
// instance data. Business payloads may legitimately contain fields
// named like UCP annotations.
for (key, val) in map {
if matches!(key.as_str(), "default" | "const" | "examples" | "enum") {
continue;
}
let child_path = format!("{}/{}", path, key);
check_annotations(val, file, &child_path, diagnostics);
}
Expand Down Expand Up @@ -937,6 +942,31 @@ mod tests {
assert!(result.diagnostics.iter().any(|d| d.code == "E004"));
}

#[test]
fn lint_does_not_check_annotations_inside_instance_keywords() {
let mut file = NamedTempFile::new().unwrap();
writeln!(
file,
r#"{{
"$id": "https://example.com/test.json",
"type": "object",
"default": {{ "ucp_request": "invalid_value" }},
"const": {{ "ucp_response": "invalid_value" }},
"examples": [{{ "ucp_response": "invalid_value" }}],
"enum": [{{ "ucp_response": "invalid_value" }}]
}}"#
)
.unwrap();

let result = lint_file(file.path(), file.path().parent().unwrap());
assert_eq!(result.status, FileStatus::Ok);
assert!(
!result.diagnostics.iter().any(|d| d.code == "E004"),
"instance data should not produce E004: {:?}",
result.diagnostics
);
}

#[test]
fn lint_valid_ucp_annotations() {
let mut file = NamedTempFile::new().unwrap();
Expand Down
Loading