Skip to content

Commit ef1ac9a

Browse files
committed
switch to NSwag
1 parent 8236f32 commit ef1ac9a

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

WebAPI/Startup.cs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using System;
2-
using System.IO;
3-
4-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
52
using Microsoft.AspNetCore.Hosting;
63
using Microsoft.Extensions.Configuration;
74
using Microsoft.Extensions.DependencyInjection;
85

6+
using NJsonSchema;
7+
98
using Newtonsoft.Json.Converters;
109

11-
using Swashbuckle.AspNetCore.Swagger;
10+
using NSwag.AspNetCore;
1211

1312
namespace SwaggerDemo.WebAPI
1413
{
@@ -28,36 +27,23 @@ public void ConfigureServices(IServiceCollection services)
2827
.AddApiExplorer()
2928
.AddJsonFormatters()
3029
.AddJsonOptions(_ => { _.SerializerSettings.Converters.Add(new StringEnumConverter()); });
31-
32-
services.AddSwaggerGen(
33-
_ =>
34-
{
35-
_.SwaggerDoc("v1", new Info { Title = "WebAPI", Version = "v1", Contact = new Contact { Name = "CaringDev" } });
36-
_.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "WebAPI.xml"));
37-
_.IgnoreObsoleteActions();
38-
_.DescribeAllEnumsAsStrings();
39-
});
4030
}
4131

4232
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
4333
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
4434
{
4535
if (env.IsDevelopment())
4636
{
47-
app
48-
.UseDeveloperExceptionPage()
49-
.UseSwaggerUI(
50-
_ =>
51-
{
52-
_.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAPI V1");
53-
_.ShowJsonEditor();
54-
_.EnabledValidator();
55-
});
37+
app.UseDeveloperExceptionPage().UseSwaggerUi(
38+
typeof(Startup).Assembly,
39+
s =>
40+
{
41+
s.GeneratorSettings.DefaultEnumHandling = EnumHandling.String;
42+
s.UseJsonEditor = true;
43+
});
5644
}
5745

58-
app
59-
.UseMvc()
60-
.UseSwagger();
46+
app.UseMvc();
6147
}
6248
}
6349
}

WebAPI/WebAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
20-
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
20+
<PackageReference Include="NSwag.AspNetCore" Version="11.19.1" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

0 commit comments

Comments
 (0)