-
-
Notifications
You must be signed in to change notification settings - Fork 158
Validations Send source.pointer #371
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
Merged
jaredcnance
merged 8 commits into
json-api-dotnet:master
from
rtablada:rt/validations-422
Aug 8, 2018
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a050acd
feat: Error should accept objects for source
rtablada 79fb285
feat: add 'GetPublicAttributeName' to ContextGraph
rtablada efa4aa7
Merge branch 'rt/get-context-property' into rt/validations-422
rtablada 30c531d
wip: new 422 validation errors with source.pointer
rtablada 0e17059
feat: validations send source.pointer
rtablada b841433
fix: handle 'GetPublicAttributeName' null and mock for tests
rtablada 524232e
feat: throw 422 status code when validation fails
rtablada 7e22eeb
feat: obsolete method ConvertToErrorCollection
rtablada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Extensions | |
{ | ||
public static class ModelStateExtensions | ||
{ | ||
public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary modelState) | ||
public static ErrorCollection ConvertToErrorCollection<T>(this ModelStateDictionary modelState, IContextGraph contextGraph) | ||
{ | ||
ErrorCollection collection = new ErrorCollection(); | ||
foreach (var entry in modelState) | ||
|
@@ -16,10 +16,19 @@ public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary | |
|
||
foreach (var modelError in entry.Value.Errors) | ||
{ | ||
var attrName =contextGraph.GetPublicAttributeName<T>(entry.Key); | ||
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. let's do this lookup outside this loop since 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. 👍 |
||
|
||
if (modelError.Exception is JsonApiException jex) | ||
collection.Errors.AddRange(jex.GetError().Errors); | ||
else | ||
collection.Errors.Add(new Error(400, entry.Key, modelError.ErrorMessage, modelError.Exception != null ? ErrorMeta.FromException(modelError.Exception) : null)); | ||
collection.Errors.Add(new Error( | ||
status: 422, | ||
title: entry.Key, | ||
detail: modelError.ErrorMessage, | ||
meta: modelError.Exception != null ? ErrorMeta.FromException(modelError.Exception) : null, | ||
source: new { | ||
pointer = $"/data/attributes/{attrName}" | ||
})); | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
So, that we don't have to release this in a major version, let's leave the original implementation and deprecate it using the
[Obsolete("Use the generic overload instead")]
. This prevents us from breaking anyone that is calling this API directly.Also, I've recently been leaning towards the idea of depending on the staticdisregard, that's going to be too big of an issue to bite off right now (i.e. there will be broken tests)ContextGraph.Instance
rather than injecting everywhere. I haven't found many reasons theContextGraph
should change after app start. Thoughts?Uh oh!
There was an error while loading. Please reload this page.
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.
🤔 for
ContextGraph.Instance
I wonder if that's safe given possible different versions of the API running at once with different context graphs?If
ContextGraph.Instance
is used other places that could still be an issue there, but IDK if we'd want to tie this down too?