Last active
February 24, 2022 22:19
-
-
Save yanandrey/44336d8a22d4a5744d947d8c4a508751 to your computer and use it in GitHub Desktop.
Swagger Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk.Web"> | |
<PropertyGroup> | |
<TargetFramework>net5.0</TargetFramework> | |
</PropertyGroup> | |
<PropertyGroup> | |
<GenerateDocumentationFile>true</GenerateDocumentationFile> | |
<NoWarn>$(NoWarn);1591</NoWarn> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SwaggerServiceCollection | |
{ | |
public static IServiceCollection AddSwaggerServices(this IServiceCollection services) | |
{ | |
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", new OpenApiInfo | |
{ | |
Title = "Api", | |
Version = "v1" | |
}); | |
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { | |
In = ParameterLocation.Header, | |
Description = "'Bearer' + JWT Token", | |
Name = "Authorization", | |
Type = SecuritySchemeType.ApiKey | |
}); | |
c.AddSecurityRequirement(new OpenApiSecurityRequirement { | |
{ | |
new OpenApiSecurityScheme | |
{ | |
Reference = new OpenApiReference | |
{ | |
Type = ReferenceType.SecurityScheme, | |
Id = "Bearer" | |
} | |
}, | |
new string[] { } | |
} | |
}); | |
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; | |
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); | |
}); | |
return services; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment