-
Notifications
You must be signed in to change notification settings - Fork 9k
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
fix(spec): format validation errors for nested parameters #9775
Conversation
As discussed we need to identify parameter name and use known convention for the path (lodash). So given I have this error message returned from validation engine: Suffix form:
Prefix form:
|
@@ -494,12 +494,38 @@ export const validationErrors = (state, pathMethod) => { | |||
let paramValues = state.getIn(["meta", "paths", ...pathMethod, "parameters"], fromJS([])) | |||
const result = [] | |||
|
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.
How about doing the following?
if (paramValues.length === 0) return result
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.
Is this to make it more clear what's happening if we don't have these values?
If so, makes sense to me.
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.
Is this to make it more clear what's happening if we don't have these values?
Well primary factor is performance here. This is not a memoized selector, which means it's executing always fully. We want to return as soon as we can to avoid logic of creating inner functions and performing the reductions as soon as possible.
src/core/plugins/spec/selectors.js
Outdated
@@ -494,12 +494,38 @@ export const validationErrors = (state, pathMethod) => { | |||
let paramValues = state.getIn(["meta", "paths", ...pathMethod, "parameters"], fromJS([])) |
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.
let paramValues = state.getIn(["meta", "paths", ...pathMethod, "parameters"], fromJS([])) | |
const paramValues = state.getIn(["meta", "paths", ...pathMethod, "parameters"], fromJS([])) |
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.
LGTM! Nicely done. The logic of error extraction and formatting is complex but it's concentrated in single place which is great. I left two comments to consider before merging.
Refs #9774
The array parameters should now get
index
of the value where the error is instead of the undefinedpropKey
. We should also go recursively into the nested errors to get a proper error message.With these changes, the validation errors for this example input:
should now show up as:
We might want to try formatting them differently, ex.
a.b.c: <error_message>
ora[b][c]: <error_message>
I was also wondering if (perhaps in a separate issue/PR) we should show the names of the parameters. These are the values we get from
swagger-ui/src/core/plugins/spec/selectors.js
Line 494 in 2dcc387
If we got the names of the parameters from the keys, we could format the message as
param: a: b: c: <error_message>
so the actual place of the error would be visible in case if we have more than one parameter for the request.