Skip to content

Commit 082fec7

Browse files
author
Ahad Chowdhury
committed
Add Swagger and Swagger UI
The Swagger JSON object can be accessed at "swagger/v1/swagger.json". The Swagger UI can be accessed at "/" (home) path. The Swagger UI can be used to test any image directly.
1 parent b580fd9 commit 082fec7

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

webapi/Connery.WebApi.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<ProjectReference Include="..\lib\Connery.Lib.csproj" />
99
<Content Include="MLModel.zip" />
1010
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.3.1" />
14+
</ItemGroup>
1115

1216

1317
</Project>

webapi/Properties/launchSettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"IIS Express": {
1313
"commandName": "IISExpress",
1414
"launchBrowser": true,
15-
"launchUrl": "weatherforecast",
15+
"launchUrl": "",
1616
"environmentVariables": {
1717
"ASPNETCORE_ENVIRONMENT": "Development"
1818
}
1919
},
20-
"Connery.Web": {
20+
"Connery.WebApi": {
2121
"commandName": "Project",
2222
"launchBrowser": true,
23-
"launchUrl": "weatherforecast",
23+
"launchUrl": "",
2424
"applicationUrl": "https://localhost:5001;http://localhost:5000",
2525
"environmentVariables": {
2626
"ASPNETCORE_ENVIRONMENT": "Development"

webapi/Startup.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using System.Reflection;
67
using Microsoft.AspNetCore.Builder;
78
using Microsoft.AspNetCore.Hosting;
89
using Microsoft.AspNetCore.HttpsPolicy;
@@ -11,6 +12,7 @@
1112
using Microsoft.Extensions.DependencyInjection;
1213
using Microsoft.Extensions.Hosting;
1314
using Microsoft.Extensions.Logging;
15+
using Microsoft.OpenApi.Models;
1416

1517
namespace Connery.WebApi
1618
{
@@ -27,11 +29,39 @@ public Startup(IConfiguration configuration)
2729
public void ConfigureServices(IServiceCollection services)
2830
{
2931
services.AddControllers();
32+
services.AddSwaggerGen(c =>
33+
{
34+
c.SwaggerDoc("v1", new OpenApiInfo
35+
{
36+
Version = "v1",
37+
Title = "Connery Web API",
38+
Description = "A simple fruit-image-classifier",
39+
Contact = new OpenApiContact
40+
{
41+
Name = "Mohammad Abdul Ahad Chowdhury",
42+
Email = "ahadc@maacpiash.com",
43+
Url = new Uri("https://www.maacpiash.com"),
44+
},
45+
License = new OpenApiLicense
46+
{
47+
Name = "MIT",
48+
Url = new Uri("https://github.com/maacpiash/Connery/blob/master/LICENSE"),
49+
}
50+
});
51+
});
3052
}
3153

3254
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
3355
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3456
{
57+
58+
app.UseSwagger();
59+
app.UseSwaggerUI(c =>
60+
{
61+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Connery Web API");
62+
c.RoutePrefix = string.Empty;
63+
});
64+
3565
if (env.IsDevelopment())
3666
{
3767
app.UseDeveloperExceptionPage();

0 commit comments

Comments
 (0)