Skip to content

Commit 8334f57

Browse files
committed
feat: adding lib to proper generate HTTP results based on Results (see dotnet/aspnetcore#44988)
1 parent c4bce90 commit 8334f57

File tree

6 files changed

+14
-10
lines changed

6 files changed

+14
-10
lines changed

src/MyBlog.Web.Api/Extensions/SwaggerExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.OpenApi.Models;
2+
using Vernou.Swashbuckle.HttpResultsAdapter;
23

34
namespace MyBlog.Web.Api.Extensions
45
{
@@ -8,12 +9,14 @@ public static void AddSwagger(this IServiceCollection services)
89
{
910
services.AddSwaggerGen(option =>
1011
{
12+
// See https://github.com/dotnet/aspnetcore/issues/44988
13+
option.OperationFilter<HttpResultsOperationFilter>();
1114
option.SwaggerDoc("v1", new OpenApiInfo { Title = "MyBlog WebAPI", Version = "v1" });
1215
option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
1316
{
1417
In = ParameterLocation.Header,
1518
Description = "Please enter a valid token",
16-
Name = "Authorization",
19+
Name = "Authorization",
1720
Type = SecuritySchemeType.Http,
1821
BearerFormat = "JWT",
1922
Scheme = "Bearer"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
namespace MyBlog.Web.Api.Models
22
{
33
public record CommentResponseViewModel(
4-
Guid Id,
5-
string Content,
4+
Guid Id,
5+
string Content,
66
string UserName,
77
DateTime CreatedAt);
88
}

src/MyBlog.Web.Api/Models/PostResponseViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
public record PostResponseViewModel(
44
Guid Id,
5-
string Title,
6-
string Summary,
7-
string Content,
8-
long ViewCount,
9-
DateTime PublishDate,
5+
string Title,
6+
string Summary,
7+
string Content,
8+
long ViewCount,
9+
DateTime PublishDate,
1010
string AuthorName,
1111
int CommentsCount);
1212
}

src/MyBlog.Web.Api/MyBlog.Web.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.8" />
1212
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" />
1313
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.8.1" />
14+
<PackageReference Include="Vernou.Swashbuckle.HttpResultsAdapter" Version="1.0.2" />
1415
</ItemGroup>
1516

1617
<ItemGroup>

src/MyBlog.Web.Api/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@
3838
}
3939
}
4040
}
41-
}
41+
}

src/MyBlog.Web.Api/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"Microsoft.AspNetCore": "Warning"
66
}
77
}
8-
}
8+
}

0 commit comments

Comments
 (0)