-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathOpenApiStartup.cs
More file actions
41 lines (35 loc) · 1.24 KB
/
OpenApiStartup.cs
File metadata and controls
41 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Reflection;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.OpenApi.Swashbuckle;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.SwaggerGen;
using TestBuildingBlocks;
namespace OpenApiTests;
public class OpenApiStartup<TDbContext> : TestableStartup<TDbContext>
where TDbContext : TestableDbContext
{
public override void ConfigureServices(IServiceCollection services)
{
base.ConfigureServices(services);
services.AddOpenApiForJsonApi(SetupSwaggerGenAction);
}
protected override void SetJsonApiOptions(JsonApiOptions options)
{
base.SetJsonApiOptions(options);
options.UseRelativeLinks = true;
options.IncludeTotalResourceCount = true;
}
protected virtual void SetupSwaggerGenAction(SwaggerGenOptions options)
{
string documentationPath = Path.ChangeExtension(Assembly.GetExecutingAssembly().Location, ".xml");
options.IncludeXmlComments(documentationPath);
}
public override void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseJsonApi();
app.UseSwagger();
app.UseEndpoints(endpoints => endpoints.MapControllers());
}
}