Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 9782b08

Browse files
committed
Changes per discussion
1 parent 25aefe0 commit 9782b08

File tree

11 files changed

+24
-412
lines changed

11 files changed

+24
-412
lines changed

src/Microsoft.AspNetCore.Mvc.ApiExplorer/ProblemDetailsApiDescriptionProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public void OnProvidersExecuting(ApiDescriptionProviderContext context)
4747
}
4848
}
4949

50+
// We don't have a good way to signal a "default" response type. We'll use 0 to indicate this until we come up
51+
// with something better.
5052
apiDescription.SupportedResponseTypes.Add(CreateProblemResponse(statusCode: 0));
5153
}
5254
}

src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ public virtual BadRequestObjectResult BadRequest(ModelStateDictionary modelState
15031503
/// </summary>
15041504
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
15051505
[NonAction]
1506-
public virtual BadRequestObjectResult ValidationProblem(ValidationProblemDetails descriptor)
1506+
public virtual ActionResult ValidationProblem(ValidationProblemDetails descriptor)
15071507
{
15081508
if (descriptor == null)
15091509
{
@@ -1518,7 +1518,7 @@ public virtual BadRequestObjectResult ValidationProblem(ValidationProblemDetails
15181518
/// </summary>
15191519
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
15201520
[NonAction]
1521-
public virtual BadRequestObjectResult ValidationProblem(ModelStateDictionary modelStateDictionary)
1521+
public virtual ActionResult ValidationProblem(ModelStateDictionary modelStateDictionary)
15221522
{
15231523
if (modelStateDictionary == null)
15241524
{
@@ -1535,7 +1535,7 @@ public virtual BadRequestObjectResult ValidationProblem(ModelStateDictionary mod
15351535
/// </summary>
15361536
/// <returns>The created <see cref="BadRequestObjectResult"/> for the response.</returns>
15371537
[NonAction]
1538-
public virtual BadRequestObjectResult ValidationProblem()
1538+
public virtual ActionResult ValidationProblem()
15391539
{
15401540
var validationProblem = new ValidationProblemDetails(ModelState);
15411541
return new BadRequestObjectResult(validationProblem);

src/Microsoft.AspNetCore.Mvc.Core/DependencyInjection/MvcCoreServiceCollectionExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ internal static void AddMvcCoreServices(IServiceCollection services)
204204
services.TryAddTransient<RequestSizeLimitFilter>();
205205
services.TryAddTransient<DisableRequestSizeLimitFilter>();
206206

207-
// Action Filters
208-
services.TryAddTransient<ProblemDetailsFilter>();
209-
210207
// Error description
211208
services.TryAddSingleton<IErrorDescriptionFactory, DefaultErrorDescriptorFactory>();
212209

src/Microsoft.AspNetCore.Mvc.Core/Infrastructure/IErrorDescriptorProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@ public interface IErrorDescriptorProvider
99
int Order { get; }
1010

1111
void OnProvidersExecuting(ErrorDescriptionContext context);
12-
13-
void OnProvidersExecuted(ErrorDescriptionContext context);
1412
}
1513
}

src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultErrorDescriptorFactory.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Linq;
67
using Microsoft.AspNetCore.Mvc.Abstractions;
@@ -14,11 +15,26 @@ public class DefaultErrorDescriptorFactory : IErrorDescriptionFactory
1415

1516
public DefaultErrorDescriptorFactory(IEnumerable<IErrorDescriptorProvider> providers)
1617
{
18+
if (providers == null)
19+
{
20+
throw new ArgumentNullException(nameof(providers));
21+
}
22+
1723
_providers = providers.OrderBy(p => p.Order).ToArray();
1824
}
1925

2026
public object CreateErrorDescription(ActionDescriptor actionDescriptor, object result)
2127
{
28+
if (actionDescriptor == null)
29+
{
30+
throw new ArgumentNullException(nameof(actionDescriptor));
31+
}
32+
33+
if (result == null)
34+
{
35+
throw new ArgumentNullException(nameof(result));
36+
}
37+
2238
var context = new ErrorDescriptionContext(actionDescriptor)
2339
{
2440
Result = result,
@@ -29,11 +45,6 @@ public object CreateErrorDescription(ActionDescriptor actionDescriptor, object r
2945
_providers[i].OnProvidersExecuting(context);
3046
}
3147

32-
for (var i = _providers.Length - 1; i >= 0; i--)
33-
{
34-
_providers[i].OnProvidersExecuted(context);
35-
}
36-
3748
return context.Result ?? result;
3849
}
3950
}

src/Microsoft.AspNetCore.Mvc.Core/Internal/ProblemDetailsFilter.cs

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/Microsoft.AspNetCore.Mvc.Core/ProblemDetailsAttribute.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,14 @@
33

44
using System;
55
using Microsoft.AspNetCore.Mvc.Filters;
6-
using Microsoft.AspNetCore.Mvc.Internal;
7-
using Microsoft.Extensions.DependencyInjection;
86

97
namespace Microsoft.AspNetCore.Mvc
108
{
119
/// <summary>
12-
/// Adds an <see cref="IFilterMetadata"/> that enhances some basic 4xx client error responses.
13-
/// <para>
14-
/// The <see cref="ProblemDetailsAttribute"/> adds an <see cref="IActionFilter"/> that adds details to the HTTP
15-
/// response, when the action signature matches certain patterns. By default, a <see cref="ProblemDetails"/>
16-
/// is returned in the response body. This can be further configured by registering instances of
17-
/// <see cref="Infrastructure.IErrorDescriptorProvider"/> in the service container.
18-
/// </para>
19-
/// Patterns matched by the filter include:
20-
/// <list>
21-
/// <item>400 <see cref="StatusCodeResult"/> on any action which participates in model binding.</item>
22-
/// <item>404 <see cref="StatusCodeResult"/> on any action with an <c>id</c> parameter.</item>
23-
/// </list>
10+
/// Adds an <see cref="IFilterMetadata"/> that indicates to the framework that the current action conforms to well-known API behavior.
2411
/// </summary>
2512
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
26-
public class ProblemDetailsAttribute : Attribute, IFilterFactory
13+
public class ProblemDetailsAttribute : Attribute, IFilterMetadata
2714
{
28-
/// <inheritdoc />
29-
public bool IsReusable => true;
30-
31-
/// <inheritdoc />
32-
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
33-
{
34-
if (serviceProvider == null)
35-
{
36-
throw new ArgumentNullException(nameof(serviceProvider));
37-
}
38-
39-
return serviceProvider.GetRequiredService<ProblemDetailsFilter>();
40-
}
4115
}
4216
}

src/Microsoft.AspNetCore.Mvc.Core/Properties/Resources.Designer.cs

Lines changed: 0 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.AspNetCore.Mvc.Core/Resources.resx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,4 @@
415415
<data name="ValidationProblemDescription_Title" xml:space="preserve">
416416
<value>One or more validation errors occured.</value>
417417
</data>
418-
<data name="ProblemDetails_400_Title" xml:space="preserve">
419-
<value>400 Bad Request</value>
420-
</data>
421-
<data name="ProblemDetails_404_Title" xml:space="preserve">
422-
<value>Resource with the specified id could not be found.</value>
423-
</data>
424-
<data name="ProblemDetails_415_Title" xml:space="preserve">
425-
<value>The request entity is in a format that is not supported by the requested resource.</value>
426-
</data>
427418
</root>

0 commit comments

Comments
 (0)