|
@@ -9,6 +9,9 @@ using MTWorkHR.Application.Filters;
|
|
using MTWorkHR.Application.StartupService;
|
|
using MTWorkHR.Application.StartupService;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MTWorkHR.Infrastructure.DBContext;
|
|
using MTWorkHR.Infrastructure.DBContext;
|
|
|
|
+using Microsoft.AspNetCore.Mvc.Controllers;
|
|
|
|
+using Microsoft.OpenApi.Models;
|
|
|
|
+using MTWorkHR.API.Swagger;
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
@@ -40,15 +43,63 @@ builder.Services.Configure<ApiBehaviorOptions>(options =>
|
|
});
|
|
});
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
-builder.Services.AddSwaggerGen();
|
|
|
|
|
|
+//builder.Services.AddSwaggerGen();
|
|
|
|
+//--------------------------
|
|
|
|
+builder.Services.AddSwaggerGen(swagger =>
|
|
|
|
+{
|
|
|
|
+ //This is to apply global headers for all requests
|
|
|
|
+ swagger.OperationFilter<HeaderOperationFilter>();
|
|
|
|
+
|
|
|
|
+ //This is to export enums to front
|
|
|
|
+ swagger.SchemaFilter<EnumSchemaFilter>();
|
|
|
|
+
|
|
|
|
+ //This is to generate the Default UI of Swagger Documentation
|
|
|
|
+ swagger.SwaggerDoc("v1", new OpenApiInfo
|
|
|
|
+ {
|
|
|
|
+ Version = "v1",
|
|
|
|
+ Title = "MTWorkHR.API",
|
|
|
|
+ Description = "MTWorkHR.API"
|
|
|
|
+ });
|
|
|
|
|
|
|
|
+ swagger.CustomOperationIds(
|
|
|
|
+ d => (d.ActionDescriptor as ControllerActionDescriptor)?.ControllerName + (d.ActionDescriptor as ControllerActionDescriptor)?.ActionName
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // To Enable authorization using Swagger (JWT)
|
|
|
|
+ swagger.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
|
|
|
|
+ {
|
|
|
|
+ Name = "Authorization",
|
|
|
|
+ Type = SecuritySchemeType.ApiKey,
|
|
|
|
+ Scheme = "Bearer",
|
|
|
|
+ BearerFormat = "JWT",
|
|
|
|
+ In = ParameterLocation.Header,
|
|
|
|
+ Description = "Enter 'Bearer' [space] and then your valid token in the text input below.\r\n\r\nExample: \"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9\"",
|
|
|
|
+ });
|
|
|
|
+ swagger.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
|
|
+ {
|
|
|
|
+ {
|
|
|
|
+ new OpenApiSecurityScheme
|
|
|
|
+ {
|
|
|
|
+ Reference = new OpenApiReference
|
|
|
|
+ {
|
|
|
|
+ Type = ReferenceType.SecurityScheme,
|
|
|
|
+ Id = "Bearer"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ new string[] {}
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+});
|
|
|
|
+//--------------------------
|
|
var app = builder.Build();
|
|
var app = builder.Build();
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
// Configure the HTTP request pipeline.
|
|
// if (app.Environment.IsDevelopment())
|
|
// if (app.Environment.IsDevelopment())
|
|
// {
|
|
// {
|
|
app.UseSwagger();
|
|
app.UseSwagger();
|
|
-app.UseSwaggerUI();
|
|
|
|
|
|
+//app.UseSwaggerUI();
|
|
|
|
+app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MTWorkHR.API v1"));
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|