10
10
using CompanyService . Interfaces ;
11
11
using CompanyService . Services ;
12
12
using Microsoft . EntityFrameworkCore ;
13
+ using Microsoft . OpenApi . Models ;
13
14
14
15
namespace WebAPI
15
16
{
@@ -32,7 +33,7 @@ public void ConfigureServices(IServiceCollection services)
32
33
//Enable CORS
33
34
services . AddCors ( c =>
34
35
{
35
- c . AddPolicy ( "AllowOrigin " , options => options . AllowAnyOrigin ( ) . AllowAnyMethod ( )
36
+ c . AddPolicy ( "ApiCorsPolicy " , options => options . AllowAnyOrigin ( ) . AllowAnyMethod ( )
36
37
. AllowAnyHeader ( ) ) ;
37
38
} ) ;
38
39
@@ -47,16 +48,22 @@ public void ConfigureServices(IServiceCollection services)
47
48
services . AddControllers ( ) ;
48
49
services . AddTransient < IEmployeeService , EmployeeService > ( ) ;
49
50
services . AddTransient < IDepartmentService , DepartmentService > ( ) ;
51
+ services . AddSwaggerGen ( c =>
52
+ {
53
+ c . SwaggerDoc ( "v1" , new OpenApiInfo { Title = "Company API" , Version = "v1" } ) ;
54
+ } ) ;
50
55
}
51
56
52
57
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
53
58
public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
54
59
{
55
- app . UseCors ( options => options . AllowAnyOrigin ( ) . AllowAnyMethod ( ) . AllowAnyHeader ( ) ) ;
56
60
if ( env . IsDevelopment ( ) )
57
61
{
58
62
app . UseDeveloperExceptionPage ( ) ;
63
+ app . UseSwagger ( ) ;
64
+ app . UseSwaggerUI ( c => c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "Company API v1" ) ) ;
59
65
}
66
+ app . UseCors ( "ApiCorsPolicy" ) ;
60
67
61
68
app . UseRouting ( ) ;
62
69
0 commit comments