public void IncludeXmlCommentsIfExists_NullAssembly_ThrowsArgumentNullException() => Assert.Throws <ArgumentNullException>(() => { SwaggerGenOptionsExtensions.IncludeXmlCommentsIfExists( new SwaggerGenOptions(), (Assembly)null); });
public void IncludeXmlCommentsIfExists_NullOptions_ThrowsArgumentNullException() => Assert.Throws <ArgumentNullException>(() => { SwaggerGenOptionsExtensions.IncludeXmlCommentsIfExists( null, typeof(SwaggerGenOptionsExtensionsTest).GetTypeInfo().Assembly); });
/// <summary> /// Add swagger to the application /// </summary> /// <param name="services">The services registered</param> /// <returns>The service collection pipeline of registered services.</returns> public static IServiceCollection AddSwaggerToAPI(this IServiceCollection services) { return services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); // Versioned API Example c.SwaggerDoc("v2", new OpenApiInfo { Title = "My API", Version = "v2" }); SwaggerGenOptionsExtensions.DescribeAllEnumsAsStrings(c); c.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"API.xml")); }); }
public void InstallServices(IServiceCollection services, IConfiguration configuration) { // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(SwaggerGenOptionsExtensions => { SwaggerGenOptionsExtensions.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "Vehicle API", Description = "A simple example ASP.NET Core Web API", TermsOfService = new Uri("https://example.com/terms"), Contact = new OpenApiContact { Name = "serhii", Email = string.Empty, Url = new Uri("https://example.com/name"), }, License = new OpenApiLicense { Name = "Use under LICX", Url = new Uri("https://example.com/license"), } }); SwaggerGenOptionsExtensions.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the bearer scheme", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey }); SwaggerGenOptionsExtensions.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Id = "Bearer", Type = ReferenceType.SecurityScheme } }, new List <string>() } }); }); }
public void IncludeXmlCommentsIfExists_XmlFileExistsWithAssemblyCodeBase_XmlCommentsFileAdded() { var assembly = typeof(SwaggerGenOptionsExtensionsTest).GetTypeInfo().Assembly; var xmlFilePath = Path.ChangeExtension(new Uri(assembly.CodeBase).AbsolutePath, ".xml"); File.WriteAllText(xmlFilePath, "<?xml version=\"1.0\"?><doc></doc>"); var options = new SwaggerGenOptions(); try { var actualOptions = SwaggerGenOptionsExtensions.IncludeXmlCommentsIfExists( options, assembly); Assert.Same(options, actualOptions); } finally { EnsureFileDeleted(xmlFilePath); } }