private void AddSwaggerJsonAndUi(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions c) { var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }
private void AddSwaggerApiVersionDescriptions(IServiceCollection services, Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions options) { var provider = services.BuildServiceProvider() .GetRequiredService <IApiVersionDescriptionProvider>(); // 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, new OpenApiInfo() { Version = description.GroupName, Title = "ChummerHub", Description = "Description for API " + description.GroupName + " to store and search Chummer Xml files", Contact = new OpenApiContact { Name = "Archon Megalon", Email = "*****@*****.**", }, License = new OpenApiLicense { Name = "License", Url = new Uri("https://github.com/chummer5a/chummer5a/blob/master/LICENSE.txt"), } }); } }
public static void AddOAuthSecurity(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions setup) { var flows = new OpenApiOAuthFlows(); flows.ClientCredentials = new OpenApiOAuthFlow() { TokenUrl = new Uri(OAuthSettings.TokenUrl, UriKind.Relative), Scopes = OAuthSettings.Scopes }; var oauthScheme = new OpenApiSecurityScheme() { Type = SecuritySchemeType.OAuth2, Description = "OAuth2 Description", Name = OAuthSettings.AuthHeaderName, In = ParameterLocation.Query, Flows = flows, Scheme = OAuthSettings.SchemeName, }; //securityrDefinition setup.AddSecurityDefinition("Bearer", oauthScheme); //securityrRequirements var securityrRequirements = new OpenApiSecurityRequirement(); securityrRequirements.Add(oauthScheme, new List <string>() { }); setup.AddSecurityRequirement(securityrRequirements); }
internal static void AddSwaggerAuthorizeBearer(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions x) { x.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "OnlineShop Api" }); x.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer", BearerFormat = "JWT", Description = "Input your Bearer token in this format - Bearer {your token here} to access this API", }); x.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer", }, Scheme = "Bearer", Name = "Bearer", In = ParameterLocation.Header, }, new List <string>() }, }); }
private static void AddXmlComments(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions options, params string[] projectNames) { foreach (var projectName in projectNames) { options.IncludeXmlComments(Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, projectName + ".xml")); } }
private void SetupSwaggerGen(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions options) { var info = new OpenApiInfo { Title = "My API", Version = "v1" }; options.SwaggerDoc("v1", info); }
/// <summary> /// Swagger documentation XML document /// </summary> /// <param name="c"></param> private static void IncludeXmlDocument(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions c) { // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{GetAssemblyName()}.xml"; string xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }
public static void Filter3rdPartyControllers(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions c, string currentAssemblyName) // for swagger { c.DocInclusionPredicate((docName, apiDesc) => { // Filter out 3rd party controllers var assemblyName = ((ControllerActionDescriptor)apiDesc.ActionDescriptor).ControllerTypeInfo.Assembly.GetName().Name; return(currentAssemblyName == assemblyName); }); }
internal static void AddSwaggerXml(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions c) { var xmlFiles = Directory.GetFiles(AppContext.BaseDirectory, "*.xml"); foreach (var xmlFile in xmlFiles) { c.IncludeXmlComments(xmlFile); } }
/// <summary> /// 获取api文档xml文件的路径 /// </summary> /// <param name="c"></param> /// <param name="name"></param> private static void GetXmlCommentsPath(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions c, string name) { var fileName = string.Format(@"{0}.xml", name); var file = Path.Combine(AppContext.BaseDirectory, fileName); if (File.Exists(file)) { c.IncludeXmlComments(file); } }
private void AddSwaggerSecurityDefinition(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions c, AuthenticationOptions authenticationOptions) { c.AddSecurityDefinition("aad-jwt", new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2, Flows = new OpenApiOAuthFlows { Implicit = new OpenApiOAuthFlow { AuthorizationUrl = new Uri(authenticationOptions.AuthorizationUrl), Scopes = DelegatedPermissions.All.ToDictionary(p => $"{authenticationOptions.ApplicationIdUri}/{p}") } } }); }
private void SwaggerConfugure(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions options) { options.SwaggerDoc("v1", new Info { Version = "v1", Title = "NHlsOnDemand" }); //Determine base path for the application. var basePath = PlatformServices.Default.Application.ApplicationBasePath; //Set the comments path for the swagger json and ui. options.IncludeXmlComments(Path.Combine(basePath, "NHlsOnDemand.xml")); options.MapType <Guid>(() => new Schema { Type = "string", Format = "uuid", Example = Guid.NewGuid() }); options.MapType <Uri>(() => new Schema { Type = "uri", Format = "uri", Example = "http://example.com/source/id" }); }
public static void AddApiKeySecurity(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions setup) { setup.AddSecurityDefinition(OAuthSettings.AuthHeaderName, new OpenApiSecurityScheme { Type = SecuritySchemeType.ApiKey, Name = OAuthSettings.AuthHeaderName, In = ParameterLocation.Header, Description = "Please enter the API Key provided to you" }); setup.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = OAuthSettings.AuthHeaderName } }, new List <string>() } }); }
private void AddSwaggerSecurityRequirement(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions c) { c.OperationFilter <OAuthSecurityRequirementOperationFilter>(); }
public static void AddGenericBackend(this Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions options) { options.DocumentFilter <DatabaseOperations>(); }