-
-
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
Changes from 4 commits
f6c9fe0
f3f7b44
1cb1995
a9ca293
9d16115
4d0d422
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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; | ||
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. nit: |
||
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; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<VersionPrefix>2.3.2</VersionPrefix> | ||
<VersionPrefix>2.3.3</VersionPrefix> | ||
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. 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. 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. 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 |
||
<TargetFrameworks>$(NetStandardVersion)</TargetFrameworks> | ||
<AssemblyName>JsonApiDotNetCore</AssemblyName> | ||
<PackageId>JsonApiDotNetCore</PackageId> | ||
|
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.
nit:
return
on newlineThere 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.
Haha no problem