Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make error messages more consistent #2515

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion lib/vocabularies/applicator/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export type DependenciesError = ErrorObject<
export const error: KeywordErrorDefinition = {
message: ({params: {property, depsCount, deps}}) => {
const property_ies = depsCount === 1 ? "property" : "properties"
return str`must have ${property_ies} ${deps} when property ${property} is present`
const quotedDeps = (deps as string)
.split(", ")
.map((v) => `'${v}'`)
.join(", ")
return str`must have ${property_ies} ${quotedDeps} when property '${property}' is present`
},
params: ({params: {property, depsCount, deps, missingProperty}}) =>
_`{property: ${property},
Expand Down
2 changes: 1 addition & 1 deletion spec/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ describe("Validation errors", () => {
invalidData1 = {a: 0, foo: 1, baz: 3},
invalidData2 = {a: 0, bar: 2}

const msg = "must have properties foo, bar, baz when property a is present"
const msg = "must have properties 'foo', 'bar', 'baz' when property 'a' is present"

const validate = ajv.compile(schema)
shouldBeValid(validate, data)
Expand Down
Loading