diff --git a/.changeset/warm-donkeys-applaud/changes.json b/.changeset/warm-donkeys-applaud/changes.json
new file mode 100644
index 00000000..bc12303d
--- /dev/null
+++ b/.changeset/warm-donkeys-applaud/changes.json
@@ -0,0 +1,4 @@
+{
+ "releases": [{ "name": "better-ajv-errors", "type": "minor" }],
+ "dependents": []
+}
diff --git a/.changeset/warm-donkeys-applaud/changes.md b/.changeset/warm-donkeys-applaud/changes.md
new file mode 100644
index 00000000..ee0917b3
--- /dev/null
+++ b/.changeset/warm-donkeys-applaud/changes.md
@@ -0,0 +1 @@
+Include data path in CLI output
diff --git a/media/screenshot.svg b/media/screenshot.svg
index 4983ecbd..52211f49 100644
--- a/media/screenshot.svg
+++ b/media/screenshot.svg
@@ -1 +1 @@
-
\ No newline at end of file
+(paragraph,bulletList,mediaSingle,codeBlock,orderedList,heading,panel,blockquote,mediaGroup,decisionList,taskList,table,bodiedExtension,layoutSection)4|"content":[5|{>6|"type":"paragarph",|^^^^^^^^^^^👈🏽Didyoumeanparagraphhere?7|"content":[8|{9|"type":"text",@/content/0/type
\ No newline at end of file
diff --git a/src/validation-errors/__tests__/__snapshots__/enum.js.snap b/src/validation-errors/__tests__/__snapshots__/enum.js.snap
index 860494b4..ff3c3d67 100644
--- a/src/validation-errors/__tests__/__snapshots__/enum.js.snap
+++ b/src/validation-errors/__tests__/__snapshots__/enum.js.snap
@@ -38,7 +38,9 @@ Array [
"[0m [90m 1 | [39m{[0m
[0m[31m[1m>[22m[39m[90m 2 | [39m [32m\\"id\\"[39m[33m:[39m [32m\\"baz\\"[39m[0m
[0m [90m | [39m [31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m [31m[1m👈🏽 Did you mean [95mbar[31m here?[22m[39m[0m
-[0m [90m 3 | [39m}[0m",
+[0m [90m 3 | [39m}[0m
+
+ [33m@[39m [90m/id[39m",
]
`;
@@ -50,7 +52,9 @@ Array [
"[0m [90m 1 | [39m{[0m
[0m[31m[1m>[22m[39m[90m 2 | [39m [32m\\"id\\"[39m[33m:[39m [32m\\"baz\\"[39m[0m
[0m [90m | [39m [31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m [31m[1m👈🏽 Did you mean [95mbar[31m here?[22m[39m[0m
-[0m [90m 3 | [39m}[0m",
+[0m [90m 3 | [39m}[0m
+
+ [33m@[39m [90m/id[39m",
]
`;
@@ -62,6 +66,8 @@ Array [
"[0m [90m 1 | [39m{[0m
[0m[31m[1m>[22m[39m[90m 2 | [39m [32m\\"id\\"[39m[33m:[39m [32m\\"baz\\"[39m[0m
[0m [90m | [39m [31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m[31m[1m^[22m[39m [31m[1m👈🏽 Unexpected value, should be equal to one of the allowed values[22m[39m[0m
-[0m [90m 3 | [39m}[0m",
+[0m [90m 3 | [39m}[0m
+
+ [33m@[39m [90m/id[39m",
]
`;
diff --git a/src/validation-errors/__tests__/__snapshots__/required.js.snap b/src/validation-errors/__tests__/__snapshots__/required.js.snap
index 756e4664..bbec5441 100644
--- a/src/validation-errors/__tests__/__snapshots__/required.js.snap
+++ b/src/validation-errors/__tests__/__snapshots__/required.js.snap
@@ -7,6 +7,8 @@ Array [
"[0m [90m 1 | [39m{[0m
[0m[31m[1m>[22m[39m[90m 2 | [39m [32m\\"nested\\"[39m[33m:[39m {}[0m
[0m [90m | [39m [31m[1m^[22m[39m [31m[1m☹️ [95mid[31m is missing here![22m[39m[0m
-[0m [90m 3 | [39m}[0m",
+[0m [90m 3 | [39m}[0m
+
+ [33m@[39m [90m/nested[39m",
]
`;
diff --git a/src/validation-errors/base.js b/src/validation-errors/base.js
index 4a890d62..c74c68ba 100644
--- a/src/validation-errors/base.js
+++ b/src/validation-errors/base.js
@@ -1,5 +1,6 @@
import { codeFrameColumns } from '@babel/code-frame';
import { getMetaFromPath, getDecoratedDataPath } from '../json';
+import chalk from 'chalk';
export default class BaseValidationError {
constructor(
@@ -32,10 +33,19 @@ export default class BaseValidationError {
}
getCodeFrame(message, dataPath = this.options.dataPath) {
- return codeFrameColumns(this.jsonRaw, this.getLocation(dataPath), {
- highlightCode: true,
- message,
- });
+ const formattedDataPath = dataPath
+ ? chalk`\n\n {yellow @} {grey ${dataPath}}`
+ : '';
+ const codeFrame = codeFrameColumns(
+ this.jsonRaw,
+ this.getLocation(dataPath),
+ {
+ highlightCode: true,
+ message,
+ }
+ );
+
+ return codeFrame + formattedDataPath;
}
print() {