Skip to content

Commit 9d8d6f1

Browse files
committed
[r] request body attribute rename
1 parent af82017 commit 9d8d6f1

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

src/Simplify.Web.Swagger/ControllerActionsFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ private static OperationType HttpMethodToOperationType(HttpMethod method) =>
9797
private static OpenApiRequestBody CreateRequestBody(Type controllerType, DocumentFilterContext context)
9898
{
9999
var request = new OpenApiRequestBody();
100-
var attributes = controllerType.GetCustomAttributes(typeof(ProducesRequestBodyAttribute), false);
101-
100+
var attributes = controllerType.GetCustomAttributes(typeof(RequestBodyAttribute), false);
101+
102102
if (attributes.Length > 0)
103103
{
104-
var item = (ProducesRequestBodyAttribute) attributes.First();
104+
var item = (RequestBodyAttribute)attributes.First();
105105

106106
request.Content = new Dictionary<string, OpenApiMediaType>
107107
{

src/Simplify.Web.Swagger/ProducesRequestBodyAttribute.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
namespace Simplify.Web.Swagger;
4+
5+
/// <summary>
6+
/// A filter that specifies the request body received by the controller.
7+
/// </summary>
8+
public class RequestBodyAttribute : Attribute
9+
{
10+
/// <summary>
11+
/// Initializes an instance of <see cref="RequestBodyAttribute"/>.
12+
/// </summary>
13+
/// <param name="model">The request body model type.</param>
14+
public RequestBodyAttribute(Type model) => Model = model ?? throw new ArgumentNullException(nameof(model));
15+
16+
/// <summary>
17+
/// Request body model type
18+
/// </summary>
19+
public Type Model { get; private set; }
20+
}

src/TesterApp/Controllers/Api/v1/Users/CreateController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace TesterApp.Controllers.Api.v1.Users;
99
[Post("/api/v1/users")]
1010
[ApiVersion("1.0")]
1111
[Produces("application/text")]
12-
[ProducesRequestBody(typeof(UserAddViewModel))]
12+
[RequestBody(typeof(UserAddViewModel))]
1313
public class CreateController : AsyncController<UserAddViewModel>
1414
{
1515
public override async Task<ControllerResponse> Invoke()

0 commit comments

Comments
 (0)