-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partially fixed dependency error messages #4417
Changes from all commits
caa59ca
82eac95
bbae10b
72ca431
fc26e50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,29 +36,35 @@ export function transformRJSFValidationErrors< | |
let { message = '' } = rest; | ||
let property = instancePath.replace(/\//g, '.'); | ||
let stack = `${property} ${message}`.trim(); | ||
|
||
if ('missingProperty' in params) { | ||
property = property ? `${property}.${params.missingProperty}` : params.missingProperty; | ||
const currentProperty: string = params.missingProperty; | ||
let uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\./, '')}`)).title; | ||
if (uiSchemaTitle === undefined) { | ||
const uiSchemaPath = schemaPath | ||
.replace(/\/properties\//g, '/') | ||
.split('/') | ||
.slice(1, -1) | ||
.concat([currentProperty]); | ||
uiSchemaTitle = getUiOptions(get(uiSchema, uiSchemaPath)).title; | ||
} | ||
|
||
if (uiSchemaTitle) { | ||
message = message.replace(`'${currentProperty}'`, `'${uiSchemaTitle}'`); | ||
} else { | ||
const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']); | ||
|
||
if (parentSchemaTitle) { | ||
message = message.replace(`'${currentProperty}'`, `'${parentSchemaTitle}'`); | ||
const rawPropertyNames: string[] = [ | ||
...(params.deps?.split(', ') || []), | ||
params.missingProperty, | ||
params.property, | ||
].filter((item) => item); | ||
|
||
if (rawPropertyNames.length > 0) { | ||
rawPropertyNames.forEach((currentProperty) => { | ||
const path = property ? `${property}.${currentProperty}` : currentProperty; | ||
let uiSchemaTitle = getUiOptions(get(uiSchema, `${path.replace(/^\./, '')}`)).title; | ||
if (uiSchemaTitle === undefined) { | ||
// To retrieve a title from UI schema, construct a path to UI schema from `schemaPath` and `currentProperty`. | ||
// For example, when `#/properties/A/properties/B/required` and `C` are given, they are converted into `['A', 'B', 'C']`. | ||
const uiSchemaPath = schemaPath | ||
.replace(/\/properties\//g, '/') | ||
.split('/') | ||
.slice(1, -1) | ||
.concat([currentProperty]); | ||
uiSchemaTitle = getUiOptions(get(uiSchema, uiSchemaPath)).title; | ||
} | ||
} | ||
if (uiSchemaTitle) { | ||
message = message.replace(`'${currentProperty}'`, `'${uiSchemaTitle}'`); | ||
} else { | ||
const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']); | ||
if (parentSchemaTitle) { | ||
message = message.replace(`'${currentProperty}'`, `'${parentSchemaTitle}'`); | ||
} | ||
} | ||
}); | ||
|
||
stack = message; | ||
} else { | ||
|
@@ -75,6 +81,11 @@ export function transformRJSFValidationErrors< | |
} | ||
} | ||
|
||
// If params.missingProperty is undefined, it is removed from rawPropertyNames by filter((item) => item). | ||
if ('missingProperty' in params) { | ||
heath-freenome marked this conversation as resolved.
Show resolved
Hide resolved
|
||
property = property ? `${property}.${params.missingProperty}` : params.missingProperty; | ||
} | ||
|
||
Comment on lines
+85
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still needed since you are always adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this if clause as |
||
// put data in expected format | ||
return { | ||
name: keyword, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,19 +90,38 @@ export default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSch | |
let errors; | ||
if (compiledValidator) { | ||
if (typeof this.localizer === 'function') { | ||
// Missing properties need to be enclosed with quotes so that | ||
// Properties need to be enclosed with quotes so that | ||
// `AJV8Validator#transformRJSFValidationErrors` replaces property names | ||
// with `title` or `ui:title`. See #4348, #4349, and #4387. | ||
// with `title` or `ui:title`. See #4348, #4349, #4387, and #4402. | ||
(compiledValidator.errors ?? []).forEach((error) => { | ||
if (error.params?.missingProperty) { | ||
error.params.missingProperty = `'${error.params.missingProperty}'`; | ||
['missingProperty', 'property'].forEach((key) => { | ||
if (error.params?.[key]) { | ||
error.params[key] = `'${error.params[key]}'`; | ||
} | ||
}); | ||
if (error.params?.deps) { | ||
// As `error.params.deps` is the comma+space separated list of missing dependencies, enclose each dependency separately. | ||
// For example, `A, B` is converted into `'A', 'B'`. | ||
error.params.deps = error.params.deps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide a comment that simply describes what these chained statements are accomplishing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment as follows:
|
||
.split(', ') | ||
.map((v: string) => `'${v}'`) | ||
.join(', '); | ||
} | ||
}); | ||
this.localizer(compiledValidator.errors); | ||
// Revert to originals | ||
(compiledValidator.errors ?? []).forEach((error) => { | ||
if (error.params?.missingProperty) { | ||
error.params.missingProperty = error.params.missingProperty.slice(1, -1); | ||
['missingProperty', 'property'].forEach((key) => { | ||
if (error.params?.[key]) { | ||
error.params[key] = error.params[key].slice(1, -1); | ||
} | ||
}); | ||
if (error.params?.deps) { | ||
// Remove surrounding quotes from each missing dependency. For example, `'A', 'B'` is reverted to `A, B`. | ||
error.params.deps = error.params.deps | ||
.split(', ') | ||
.map((v: string) => v.slice(1, -1)) | ||
.join(', '); | ||
Comment on lines
+121
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide a comment that simply describes what these chained statements are accomplishing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a comment as follows:
|
||
} | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide a comment that simply describes what these chained statements are accomplishing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I added a comment as follows: