using System; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; namespace OnlineAssessment { /// /// Configures the Swagger generation options. /// /// This allows API versioning to define a Swagger document per API version after the /// service has been resolved from the service container. public class SwaggerConfigureOptions : IConfigureOptions { private const string OdiwareApiTitle = "API - USER"; private const string OdiwareApiDescription = "Odiware Online Assessment System - RESTful APIs for the users operation"; readonly IApiVersionDescriptionProvider provider; /// /// Initializes a new instance of the class. /// /// The provider used to generate Swagger documents. public SwaggerConfigureOptions(IApiVersionDescriptionProvider provider) => this.provider = provider; /// public void Configure(SwaggerGenOptions options) { // add a swagger document for each discovered API version // note: you might choose to skip or document deprecated API versions differently foreach (var description in provider.ApiVersionDescriptions) { options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description)); } } static OpenApiInfo CreateInfoForApiVersion(ApiVersionDescription description) { var info = new OpenApiInfo() { Title = OdiwareApiTitle, Version = description.ApiVersion.ToString(), Description = OdiwareApiDescription, Contact = new OpenApiContact() { Name = "Odiware Technologies", Email = "hr@odiware.com" }, License = new OpenApiLicense() { Name = "MIT", Url = new Uri("https://opensource.org/licenses/MIT") } }; if (description.IsDeprecated) { info.Description += " This API version has been deprecated."; } return info; } } }