-
-
Save Guifgr/041210bd9f80f6ec7f444eec9b61f6cb 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>net8.0</TargetFramework> | |
<Nullable>enable</Nullable> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<GenerateDocumentationFile>true</GenerateDocumentationFile> | |
<NoWarn>$(NoWarn);1591</NoWarn> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | |
</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