Skip to content
Open
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
30 changes: 30 additions & 0 deletions src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ fn check_refs(
}

for (key, val) in map {
// These keywords hold JSON instance data, not child schemas.
// A business payload field named `$ref` should not be resolved.
if matches!(key.as_str(), "default" | "const" | "examples" | "enum") {
continue;
}
let child_path = format!("{}/{}", path, key);
check_refs(val, file, file_dir, &child_path, root, diagnostics);
}
Expand Down Expand Up @@ -915,6 +920,31 @@ mod tests {
assert!(result.diagnostics.iter().any(|d| d.code == "E002"));
}

#[test]
fn lint_does_not_check_refs_inside_instance_keywords() {
let mut file = NamedTempFile::new().unwrap();
writeln!(
file,
r#"{{
"$id": "https://example.com/test.json",
"type": "object",
"default": {{ "$ref": "business-id" }},
"const": {{ "$ref": "business-id" }},
"examples": [{{ "$ref": "business-id" }}],
"enum": [{{ "$ref": "business-id" }}]
}}"#
)
.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 == "E002"),
"instance data should not produce E002: {:?}",
result.diagnostics
);
}

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