Skip to content

Commit 0e17059

Browse files
committed
feat: validations send source.pointer
1 parent 30c531d commit 0e17059

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/JsonApiDotNetCore/Controllers/BaseJsonApiController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public virtual async Task<IActionResult> PostAsync([FromBody] T entity)
156156
return Forbidden();
157157

158158
if (_jsonApiContext.Options.ValidateModelState && !ModelState.IsValid)
159-
return BadRequest(ModelState.ConvertToErrorCollection(_jsonApiContext.ContextGraph));
159+
return BadRequest(ModelState.ConvertToErrorCollection<T>(_jsonApiContext.ContextGraph));
160160

161161
entity = await _create.CreateAsync(entity);
162162

@@ -170,7 +170,7 @@ public virtual async Task<IActionResult> PatchAsync(TId id, [FromBody] T entity)
170170
if (entity == null)
171171
return UnprocessableEntity();
172172
if (_jsonApiContext.Options.ValidateModelState && !ModelState.IsValid)
173-
return BadRequest(ModelState.ConvertToErrorCollection(_jsonApiContext.ContextGraph));
173+
return BadRequest(ModelState.ConvertToErrorCollection<T>(_jsonApiContext.ContextGraph));
174174

175175
var updatedEntity = await _update.UpdateAsync(id, entity);
176176

src/JsonApiDotNetCore/Extensions/ModelStateExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace JsonApiDotNetCore.Extensions
66
{
77
public static class ModelStateExtensions
88
{
9-
public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary modelState, IContextGraph contextGraph)
9+
public static ErrorCollection ConvertToErrorCollection<T>(this ModelStateDictionary modelState, IContextGraph contextGraph)
1010
{
1111
ErrorCollection collection = new ErrorCollection();
1212
foreach (var entry in modelState)
@@ -16,7 +16,7 @@ public static ErrorCollection ConvertToErrorCollection(this ModelStateDictionary
1616

1717
foreach (var modelError in entry.Value.Errors)
1818
{
19-
var attrName = entry.Key;
19+
var attrName =contextGraph.GetPublicAttributeName<T>(entry.Key);
2020

2121
if (modelError.Exception is JsonApiException jex)
2222
collection.Errors.AddRange(jex.GetError().Errors);

0 commit comments

Comments
 (0)