Skip to content

Commit 0cc80eb

Browse files
committed
Added Swagger for API Documentation and set as starting page for webapi.
Audited npm package.
1 parent 58d5bc9 commit 0cc80eb

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

WebGYM/WebGYM/Startup.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Extensions.Configuration;
1616
using Microsoft.Extensions.DependencyInjection;
1717
using Microsoft.IdentityModel.Tokens;
18+
using Swashbuckle.AspNetCore.Swagger;
1819
using WebGYM.Common;
1920
using WebGYM.Concrete;
2021
using WebGYM.Interface;
@@ -114,6 +115,12 @@ public void ConfigureServices(IServiceCollection services)
114115
.AllowCredentials()
115116
.WithExposedHeaders("X-Pagination"));
116117
});
118+
119+
// Register the Swagger generator, defining 1 or more Swagger documents
120+
services.AddSwaggerGen(c =>
121+
{
122+
c.SwaggerDoc("v1", new Info { Title = "WebGym API", Version = "v1" });
123+
});
117124
}
118125

119126
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -133,6 +140,18 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
133140
app.UseAuthentication();
134141

135142
app.UseCors("CorsPolicy");
143+
// Enable middleware to serve generated Swagger as a JSON endpoint.
144+
app.UseSwagger();
145+
146+
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
147+
// specifying the Swagger JSON endpoint.
148+
app.UseSwaggerUI(c =>
149+
{
150+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebGym API V1");
151+
//Reference document: https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-2.2&tabs=visual-studio
152+
//To serve the Swagger UI at the app's root (http://localhost:<port>/), set the RoutePrefix property to an empty string:
153+
c.RoutePrefix = string.Empty;
154+
});
136155
app.UseMvc(routes =>
137156
{
138157
routes.MapRoute(

WebGYM/WebGYM/WebGYM.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
99
<PackageReference Include="Microsoft.AspNetCore.App" />
1010
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
1112
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.8.8" />
1213
</ItemGroup>
1314

gym-project/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
"zone.js": "~0.8.26"
3333
},
3434
"devDependencies": {
35-
"@angular-devkit/build-angular": "~0.10.0",
35+
"@angular-devkit/build-angular": "^0.13.0",
3636
"@angular/cli": "~7.0.6",
3737
"@angular/compiler-cli": "~7.0.0",
3838
"@angular/language-service": "~7.0.0",
39-
"@types/node": "~8.9.4",
4039
"@types/jasmine": "~2.8.8",
4140
"@types/jasminewd2": "~2.0.3",
41+
"@types/node": "~8.9.4",
4242
"codelyzer": "~4.5.0",
4343
"jasmine-core": "~2.99.1",
4444
"jasmine-spec-reporter": "~4.2.1",

0 commit comments

Comments
 (0)