-
-
Notifications
You must be signed in to change notification settings - Fork 158
Feature/#252 valid modelstate #316
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 6 commits into
json-api-dotnet:master
from
sigent:feature/#252_valid_modelstate
Jun 28, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f6c9fe0
Check if Model State is valid and throw a 400
sigent f3f7b44
Merge branch 'develop' of https://github.com/json-api-dotnet/JsonApiD…
sigent 1cb1995
Merge branch 'master' of https://github.com/sigent/JsonApiDotNetCore …
sigent a9ca293
bumped version no
sigent 9d16115
styling updates
sigent 4d0d422
added ValidateModelState as feature flag in options
sigent 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 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 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 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using JsonApiDotNetCore.Internal; | ||
using Microsoft.AspNetCore.Mvc.ModelBinding; | ||
using Microsoft.EntityFrameworkCore.Internal; | ||
|
||
namespace JsonApiDotNetCore.Extensions | ||
{ | ||
public static class ModelStateExtensions | ||
{ | ||
public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary modelState) | ||
{ | ||
ErrorCollection errors = new ErrorCollection(); | ||
foreach (var entry in modelState) | ||
{ | ||
if (!entry.Value.Errors.Any()) | ||
continue; | ||
foreach (var modelError in entry.Value.Errors) | ||
{ | ||
errors.Errors.Add(new Error(400, entry.Key, modelError.ErrorMessage, modelError.Exception != null ? ErrorMeta.FromException(modelError.Exception) : null)); | ||
} | ||
} | ||
return errors; | ||
} | ||
} | ||
} |
This file contains 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 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.
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.
Wondering if this should be a major version bump. It could break existing apps if they have annotations but aren't currently checking them. We could release this as a patch version behind a feature flag (e.g.
options.ValidateModelState
) with a default disabled value. Then in the next major release enable it by default. What do you think?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.
You could argue that if they have annotations already on their entities, then its already invalid and it's now being flagged. However, the feature flag route makes sense for a minor release :-D
Made the changes