Skip to content

Commit 027b189

Browse files
authored
Merge pull request #19 from asset-t/feature/response-body
Feature/response body
2 parents c2e3fa7 + 4db86da commit 027b189

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

src/Simplify.Web.Swagger/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [0.4] - 2023-12-21
4+
5+
### Added
6+
7+
- Response body display and usage
8+
39
## [0.3] - 2023-12-20
410

511
### Added

src/Simplify.Web.Swagger/ControllerActionsFactory.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private static ControllerAction CreateControllerAction(HttpMethod method, string
4242
Type = HttpMethodToOperationType(method),
4343
Path = route.StartsWith("/") ? route : "/" + route,
4444
Names = CreateNames(item.ControllerType),
45-
Responses = CreateResponses(item.ControllerType),
45+
Responses = CreateResponses(item.ControllerType, context),
4646
RequestBody = CreateRequestBody(item.ControllerType, context),
4747
IsAuthorizationRequired = item.Security != null && item.Security.IsAuthorizationRequired
4848
};
@@ -112,19 +112,19 @@ private static OpenApiRequestBody CreateRequestBody(Type controllerType, Documen
112112
return request;
113113
}
114114

115-
private static IDictionary<int, OpenApiResponse> CreateResponses(Type controllerType)
115+
private static IDictionary<int, OpenApiResponse> CreateResponses(Type controllerType, DocumentFilterContext context)
116116
{
117117
var items = new Dictionary<int, OpenApiResponse>();
118118

119119
var attributes = controllerType.GetCustomAttributes(typeof(ProducesResponseAttribute), false);
120120

121121
foreach (ProducesResponseAttribute item in attributes)
122-
items.Add(item.StatusCode, CreateResponse(item));
122+
items.Add(item.StatusCode, CreateResponse(item, context));
123123

124124
return items;
125125
}
126126

127-
private static OpenApiResponse CreateResponse(ProducesResponseAttribute producesResponse)
127+
private static OpenApiResponse CreateResponse(ProducesResponseAttribute producesResponse, DocumentFilterContext context)
128128
{
129129
var response = new OpenApiResponse();
130130

@@ -133,7 +133,9 @@ private static OpenApiResponse CreateResponse(ProducesResponseAttribute produces
133133
.Value;
134134

135135
foreach (var item in producesResponse.ContentTypes.Distinct())
136-
response.Content.Add(item, new OpenApiMediaType());
136+
response.Content.Add(item, producesResponse.Type is null
137+
? new OpenApiMediaType()
138+
: new () {Schema = context.SchemaGenerator.GenerateSchema(producesResponse.Type, context.SchemaRepository)});
137139

138140
return response;
139141
}

src/Simplify.Web.Swagger/Simplify.Web.Swagger.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1010
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1111

12-
<Version>0.3</Version>
12+
<Version>0.4</Version>
1313

1414
<Description>Swagger extensions for Simplify.Web web-framework</Description>
1515
<Product>Simplify</Product>

src/TesterApp/Controllers/Api/v1/Groups/GetMultipleController.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using System.Net.Mime;
2+
using Microsoft.AspNetCore.Mvc;
23
using Simplify.Web;
34
using Simplify.Web.Attributes;
45
using Simplify.Web.Json.Responses;
6+
using Simplify.Web.Swagger;
57
using TesterApp.ViewModels;
68

79
namespace TesterApp.Controllers.Api.v1.Groups;
810

911
[Get("/api/v1/groups")]
1012
[ApiVersion("1.0")]
11-
[Produces("application/json")]
12-
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IList<GroupViewModel>))]
13-
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
13+
[ProducesResponse(StatusCodes.Status200OK, typeof(IList<GroupViewModel>), MediaTypeNames.Application.Json)]
14+
[ProducesResponse(StatusCodes.Status500InternalServerError)]
1415
public class GetMultipleController : Simplify.Web.Controller
1516
{
1617
public override ControllerResponse Invoke()

0 commit comments

Comments
 (0)