Add Diagnostic provider to Schema Validation, improve JSON Pointer handling and add Dialect support#7
Conversation
…tava-diya/json-language-server into feature/schema-validation
jdesrosiers
left a comment
There was a problem hiding this comment.
Let's start organizing our tests. There should be a separate test file for each feature. So, src/features/SchemaValidation.test.ts, src/features/SyntaxValidation.test.ts, etc.
| if (pointer === "#") { | ||
| return node; | ||
| } | ||
| const segments = [...pointerSegments(pointer.slice(1))]; |
There was a problem hiding this comment.
Remember that pointer is a URI and could have URI escaped characters that need to be decoded. pointerSegments will only handle JSON Pointer escaped characters, not URI escaped characters.
| return node; | ||
| } | ||
| const segments = [...pointerSegments(pointer.slice(1))]; | ||
| const path = segments.map((s) => /^\d+$/.test(s) ? parseInt(s) : s); |
There was a problem hiding this comment.
This isn't quite right. Consider,
{
"42": ["foo"]
}Given the pointer, /42/0, the path should be ["42", 0], not [42, 0]. So, you can't just match anything that looks like an integer and parse it. You have to take the type at that location into account.
So, you won't be able to use fineNodeAtLocation for this. You'll need to walk the AST for each segment and only parse to a number if the current node is an array.
| }; | ||
|
|
||
| const formatError = (error: ErrorObject, depth = 0): string => { | ||
| let msg = error.message; |
There was a problem hiding this comment.
It's best to avoid abbreviations.
| let msg = error.message; | |
| let message = error.message; |

Description
Based on feedback from our call, i have made the following changes
build-server.ts: Added support for all JSON Schema dialects (draft-04 through draft-2020-12).SchemaValidation.ts: Replaced the instanceLocation.slice(2).split("/") path resolution withfindNodeByPointera helper Fn that uses @hyperjump/json-pointer'spointerSegmentsto correctly handle escape sequences and array indices.language-server.test.ts: Added test with property names containing / (escape sequence)