Suppress JsonPatchDocument validation (#6429)
Addresses aspnet/JsonPatch#80
This commit is contained in:
parent
de64c84610
commit
9d138affa2
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
|
|
@ -80,6 +81,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Json.Internal
|
|||
|
||||
options.FormatterMappings.SetMediaTypeMappingForFormat("json", MediaTypeHeaderValue.Parse("application/json"));
|
||||
|
||||
options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(IJsonPatchDocument)));
|
||||
options.ModelMetadataDetailsProviders.Add(new SuppressChildValidationMetadataProvider(typeof(JToken)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,6 +137,20 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InvalidOperation_AddsErrorToModelState()
|
||||
{
|
||||
// Arrange
|
||||
var input = "[{ 'op': 'invalid', 'path': 'Reviews/1/Rating', 'from': 'Reviews/0/Rating'}]".Replace("'", "\"");
|
||||
var request = GetPatchRequest(input);
|
||||
|
||||
// Act
|
||||
var response = await Client.SendAsync(request);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||
}
|
||||
|
||||
private HttpRequestMessage GetPatchRequest(string body)
|
||||
{
|
||||
return new HttpRequestMessage
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using System.Xml;
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.JsonPatch;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
||||
using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
|
|
@ -211,6 +212,11 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
},
|
||||
provider => Assert.IsType<DataAnnotationsMetadataProvider>(provider),
|
||||
provider =>
|
||||
{
|
||||
var excludeFilter = Assert.IsType<SuppressChildValidationMetadataProvider>(provider);
|
||||
Assert.Equal(typeof(IJsonPatchDocument), excludeFilter.Type);
|
||||
},
|
||||
provider =>
|
||||
{
|
||||
var excludeFilter = Assert.IsType<SuppressChildValidationMetadataProvider>(provider);
|
||||
Assert.Equal(typeof(JToken), excludeFilter.Type);
|
||||
|
|
|
|||
Loading…
Reference in New Issue