public static void SwaggerConfiguration(SwaggerGenOptions options, string apiName, string swaggerApiTitle, string swaggerDescription, IConfiguration configuration) { var email = configuration.GetSection("Swagger:Email").Get <string>(); var contactUri = configuration.GetSection("Swagger:ContactUri").Get <string>(); options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = swaggerApiTitle, Description = swaggerDescription, Contact = new OpenApiContact { Name = "Contact", Email = email, Url = new Uri(contactUri), }, License = new OpenApiLicense { Name = "All Rights Reserved", }, }); options.EnableAnnotations(); var xmlFile = $"{apiName}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); options.IncludeXmlComments(xmlPath); }
public static void AddXmlComments(this SwaggerGenOptions options) { var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); if (File.Exists(xmlPath)) { options.IncludeXmlComments(xmlPath); options.EnableAnnotations(); } }
private static void ConfigureSwagger(SwaggerGenOptions options, IServiceCollection services, IConfiguration configuration, Type startupType) { var settings = configuration.GetSection(SettingsSectionName).Get <SwaggerSettings> (); var provider = services.BuildServiceProvider().GetRequiredService <IApiVersionDescriptionProvider> (); foreach (var description in provider.ApiVersionDescriptions) { options.SwaggerDoc(description.GroupName, GetOpenApiInfo(description, settings)); } options.OperationFilter <SwaggerOperationFilter> (); options.SchemaFilter <SwaggerSchemaFilter> (); options.EnableAnnotations(); options.IncludeXmlComments(GetXmlDocumentationFile(startupType)); }
public void ConfigureSwaggerGen(SwaggerGenOptions swaggerGenOptions) { swaggerGenOptions.SwaggerGeneratorOptions.SwaggerDocs.Add(_version, new Info { Title = _title, Version = _version, Description = _description, Contact = new Contact() { Name = _contactName, Url = _contactUrl }, License = new License() { Name = _license, Url = _licenseUrl }, TermsOfService = _termsOfServiceUrl }); swaggerGenOptions.EnableAnnotations(); //swaggerGenOptions.SwaggerGeneratorOptions = new SwaggerGeneratorOptions //{ // SwaggerDocs = new Dictionary<string, Info>() // { // { // _version, // new Info // { // Title = _title, // Version = _version, // Description = _description, // Contact = new Contact() // { // Name = _contactName, // Url = _contactUrl // } // } // } // }, //}; }
private void ConfigureSwaggerGen(SwaggerGenOptions options) { options.SwaggerDoc("v1", new OpenApiInfo { Title = "FOOD DELIVERY API", Version = "v1" }); options.EnableAnnotations(); options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = @"JWT Authorization header using the Bearer scheme. Enter 'Bearer' [space] and then your token in the text input below. Example: 'Bearer 12345abcdef'", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer", }); options.IgnoreObsoleteProperties(); options.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = ParameterLocation.Header, }, new List <string>() } }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); options.IncludeXmlComments(xmlPath); }
private void ConfigureSwaggerGen(SwaggerGenOptions sw) { sw.ExampleFilters(); sw.EnableAnnotations(); sw.SwaggerDoc(version, new OpenApiInfo { Title = title, Version = version, Contact = new OpenApiContact() { Name = "Soundar", Email = "*****@*****.**", Url = new Uri("https://soundararajan.in") }, License = new OpenApiLicense { Name = "Apache 2.0", Url = new Uri("http://apache.org/licenses/LICENSE-2.0.html") } }); }
/// <summary>Configures the Open API documentation generation.</summary> public static void Generation(SwaggerGenOptions options) { options.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "TJIP Rumpelstiltskin API", Description = "Name selection application", }); // We want all actions ordered alphabetically by there relative path and grouped by their tag name // instead of their controller name. Therefor we need to EnableAnnotations and use the Tags property on // the SwaggerOperationAttribute. options.EnableAnnotations(); options.OrderActionsBy(descr => $"{descr.GroupName}-{descr.RelativePath}"); // When using this Startup for integration tests, the name of the assembly will change (to TestHost) // Therefor we are hard coding the name of the generated XML comments file to make sure that the original reference // to the assembly name will not fail: // {AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{Assembly.GetEntryAssembly().GetName().Name}.xml options.IncludeXmlComments($"Rumpelstiltskin.Api.xml"); }
/// <summary> /// Configures swagger generator for this API /// </summary> public static void Configure(this SwaggerGenOptions c) { // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); foreach (var version in GetVersions()) { c.SwaggerDoc( version, new OpenApiInfo { Title = "Product API example", Version = version }); } c.OperationFilter <RemoveVersionParameterFilter>(); c.DocumentFilter <ReplaceVersionWithExactValueInPathFilter>(); c.DocInclusionPredicate((version, desc) => { var versions = desc.ActionDescriptor.EndpointMetadata .OfType <ApiVersionAttribute>() .SelectMany(attr => attr.Versions); var maps = desc.ActionDescriptor.EndpointMetadata .OfType <MapToApiVersionAttribute>() .SelectMany(attr => attr.Versions) .ToArray(); return(versions.Any(v => $"v{v}" == version) && (!maps.Any() || maps.Any(v => $"v{v}" == version)));; }); c.EnableAnnotations(); }
/// <summary>Настройки генератора Swagger</summary> public static void FillGenOptions(SwaggerGenOptions c) { c.SwaggerDoc("Anket_v01", new OpenApiInfo { Version = "v01", Title = "AnketTest/v01/", Description = "Прием сведений анкет v01", Contact = new OpenApiContact { Name = "Аксенов Алексей", Email = "*****@*****.**" } }); // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); // включаем аннотации c.EnableAnnotations(); }
public static SwaggerGenOptions AddSwaggerGenSupport(this SwaggerGenOptions swaggerGenOptions, IHostEnvironment hostEnv, string title, string release, List <string> apiVersions = null) { if (apiVersions == null || apiVersions.Count == 0) { apiVersions = new List <string>() { "1.0" }; } string description = $"Environment: {hostEnv.EnvironmentName} {Environment.NewLine}Release: {release}"; apiVersions.ForEach(version => { swaggerGenOptions.SwaggerDoc($"v{version}", new OpenApiInfo { Title = title, Version = $"v{version}", Description = description, TermsOfService = new System.Uri("https://www.google.com/"), Contact = new OpenApiContact { Email = "*****@*****.**", Name = "My Company Support Team" }, License = new OpenApiLicense { Name = $"Copyright {DateTime.Now.Year}, My Company Inc. All rights reserved." } }); }); swaggerGenOptions.EnableAnnotations(); return(swaggerGenOptions); }
public static void EnableAnnotations(this SwaggerGenOptions options, bool enableSubTypeAnnotations) { options.EnableAnnotations( enableAnnotationsForPolymorphism: enableSubTypeAnnotations, enableAnnotationsForInheritance: enableSubTypeAnnotations); }
/// <summary> /// Enables Swagger annotations (SwaggerOperationAttribute, SwaggerParameterAttribute etc.) /// </summary> /// <param name="options"></param> public static void EnableAnnotations(this SwaggerGenOptions options) { options.EnableAnnotations( enableAnnotationsForPolymorphism: false, enableAnnotationsForInheritance: false); }
private static void ConfigureSwaggerGenerator(SwaggerGenOptions options) { options.CustomOperationIds(GetOperationId); options.SwaggerDoc(SwaggerVariables.Version, SwaggerVariables.OpenApiInfo); options.EnableAnnotations(); }