6
6
using JsonApiDotNetCore . Models ;
7
7
using JsonApiDotNetCore . Models . JsonApiDocuments ;
8
8
using Microsoft . AspNetCore . Mvc . ModelBinding ;
9
+ using Newtonsoft . Json . Serialization ;
9
10
10
11
namespace JsonApiDotNetCore . Exceptions
11
12
{
@@ -17,13 +18,13 @@ public class InvalidModelStateException : Exception
17
18
public IList < Error > Errors { get ; }
18
19
19
20
public InvalidModelStateException ( ModelStateDictionary modelState , Type resourceType ,
20
- bool includeExceptionStackTraceInErrors )
21
+ bool includeExceptionStackTraceInErrors , NamingStrategy namingStrategy )
21
22
{
22
- Errors = FromModelState ( modelState , resourceType , includeExceptionStackTraceInErrors ) ;
23
+ Errors = FromModelState ( modelState , resourceType , includeExceptionStackTraceInErrors , namingStrategy ) ;
23
24
}
24
25
25
26
private static List < Error > FromModelState ( ModelStateDictionary modelState , Type resourceType ,
26
- bool includeExceptionStackTraceInErrors )
27
+ bool includeExceptionStackTraceInErrors , NamingStrategy namingStrategy )
27
28
{
28
29
List < Error > errors = new List < Error > ( ) ;
29
30
@@ -32,9 +33,8 @@ private static List<Error> FromModelState(ModelStateDictionary modelState, Type
32
33
var propertyName = pair . Key ;
33
34
PropertyInfo property = resourceType . GetProperty ( propertyName ) ;
34
35
35
- // TODO: Need access to ResourceContext here, in order to determine attribute name when not explicitly set.
36
36
string attributeName =
37
- property ? . GetCustomAttribute < AttrAttribute > ( ) . PublicAttributeName ?? property ? . Name ;
37
+ property . GetCustomAttribute < AttrAttribute > ( ) . PublicAttributeName ?? namingStrategy . GetPropertyName ( property . Name , false ) ;
38
38
39
39
foreach ( var modelError in pair . Value . Errors )
40
40
{
0 commit comments