-
Notifications
You must be signed in to change notification settings - Fork 338
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
Improve Problem JSON Error Format for Validation #370
Improve Problem JSON Error Format for Validation #370
Conversation
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.
Good stuff here,
I suggest avoid creating a separate function and extend the fromTemplate
to take in account an additional property that can be anything we need.
packages/http/src/types.ts
Outdated
@@ -90,16 +102,37 @@ export class ProblemJsonError extends Error { | |||
return error; | |||
} | |||
|
|||
public static asValidationIssue(error: Error & { detail: IPrismDiagnostic[]; status?: number }): any { |
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.
The spec for the problem/json
says that effectively additional field apart from the standard one are accepted; I'd suggest, instead of creating a new function to handle the specific case, we could extend the fromTemplate
function to add an additional: unknown
parameter that we can add to the payload, in this way the final code should be kind of simplified.
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.
hm.. @XVincentX, did you mean fromTemplate
or fromPlainError
?
..._quantity__3__shipDate___2002-10-02T10_00_00-05_00___status___placed___complete__true__.json
Show resolved
Hide resolved
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.
Seems like something funky is going on with details, it probably shouldn't change away from being string, but the output in tests looks good. Nicely done!
ef2aa7b
to
11a39c3
Compare
@philsturgeon I took over and brought this over the finish line. I've extended the Also — for the future, the spec mandates that P.S: I'm not too happy with the way I wrote the ProblemJson implementation, but unfortunately it's required because of the way Fastify handles the the |
11a39c3
to
f0e2209
Compare
@@ -237,7 +231,9 @@ const createSpec = (specPath) => { | |||
|
|||
expect(reqRes).toMatchObject(masterFile); | |||
|
|||
expect(payload.detail).toContain("should have required property 'name'"); | |||
expect(payload.detail).toContain( |
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.
This line is less interesting than the previous assertion: checking it is moaning about required proper name. Can we assert that this new validation property has the validation we are interested in instead?
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.
I'll fix it, however all this is going to be removed soon/needs to be converted to the new harness thing — is it worth to spend time on this?
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.
Ahh yeah sorry i didnt notice it was in there. Ignore.
I'll give @chris-miaskowski some time to jump into this as well |
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.
I'm auto accepting this
Checklist
What kind of change does this PR introduce?
Feature.
What is the current behavior? What is the new behavior?
The current behavior gives validation error details as a JSON with a string (namely:
Your request body is not valid
) concatenated together.Now, the details (422 validation errors) are just that JSON but under
validation
field.detail
field is now just a string with a description of the problem. Also, in the JSON,path
field was renamed tolocation
andseverity
s field value is now represented with a string (likeError
), not a number.Does this PR introduce a breaking change?
This change might involve some changes in handling Prism-generated 422 responses.