public static string GetSwaggerEndpoint(ElectSwaggerOptions options, bool isIncludeAccessKey = true) { string swaggerEndpoint = $"/{options.SwaggerRoutePrefix}/{options.Version}/{options.SwaggerName}"; if (isIncludeAccessKey && !string.IsNullOrWhiteSpace(options.AccessKey)) { swaggerEndpoint += $"?{ElectSwaggerConstants.AccessKeyName}={options.AccessKey}"; } return(swaggerEndpoint); }
public static ElectSwaggerOptions GetOptions(IConfiguration configuration, string sectionName = "ElectSwagger") { var electSwaggerOptions = new ElectSwaggerOptions(); electSwaggerOptions.IsEnable = configuration.GetValueByEnv <bool>($"{sectionName}:{nameof(electSwaggerOptions.IsEnable)}"); electSwaggerOptions.SwaggerRoutePrefix = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.SwaggerRoutePrefix)}"); electSwaggerOptions.SwaggerName = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.SwaggerName)}"); electSwaggerOptions.Url = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.Url)}"); electSwaggerOptions.JsonViewerUrl = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.JsonViewerUrl)}"); electSwaggerOptions.Title = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.Title)}"); electSwaggerOptions.Version = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.Version)}"); electSwaggerOptions.AccessKey = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.AccessKey)}"); electSwaggerOptions.UnAuthorizeMessage = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.UnAuthorizeMessage)}"); electSwaggerOptions.AuthTokenType = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.AuthTokenType)}"); electSwaggerOptions.IsFullSchemaForType = configuration.GetValueByEnv <bool>($"{sectionName}:{nameof(electSwaggerOptions.IsFullSchemaForType)}"); electSwaggerOptions.AuthorName = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.AuthorName)}"); electSwaggerOptions.AuthorEmail = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.AuthorEmail)}"); electSwaggerOptions.AuthorWebsite = configuration.GetValueByEnv <string>($"{sectionName}:{nameof(electSwaggerOptions.AuthorWebsite)}"); electSwaggerOptions.GlobalParameters = configuration.GetListValueByEnv <OpenApiParameter>( $"{sectionName}:{nameof(electSwaggerOptions.GlobalParameters)}"); return(electSwaggerOptions); }
public static bool IsAccessUI(HttpContext httpContext, ElectSwaggerOptions options) { var pathQuery = httpContext.Request.Path.Value?.Trim('/').ToLower() ?? string.Empty; pathQuery = pathQuery.ToLowerInvariant(); var documentApiBaseUrl = options.SwaggerRoutePrefix ?? string.Empty; documentApiBaseUrl = documentApiBaseUrl.ToLowerInvariant(); var isSwaggerUi = pathQuery == documentApiBaseUrl || pathQuery == $"{documentApiBaseUrl}/index.html"; return(isSwaggerUi || httpContext.Request.IsRequestFor(options.Url)); }
public static SwaggerGenOptions AddElectSwaggerGenOptions([NotNull] SwaggerGenOptions swaggerGenOptions, [NotNull] ElectSwaggerOptions configuration) { return(AddElectSwaggerGenOptions(swaggerGenOptions, _ => { _.SwaggerRoutePrefix = configuration.SwaggerRoutePrefix; _.SwaggerName = configuration.SwaggerName; _.Url = configuration.Url; _.JsonViewerUrl = configuration.JsonViewerUrl; _.Title = configuration.Title; _.Version = configuration.Version; _.AccessKey = configuration.AccessKey; _.UnAuthorizeMessage = configuration.UnAuthorizeMessage; _.AuthTokenType = configuration.AuthTokenType; _.IsFullSchemaForType = configuration.IsFullSchemaForType; _.AuthorName = configuration.AuthorName; _.AuthorEmail = configuration.AuthorEmail; _.AuthorWebsite = configuration.AuthorWebsite; })); }
public static IServiceCollection AddElectSwagger(this IServiceCollection services, [NotNull] ElectSwaggerOptions configuration) { return(services.AddElectSwagger(_ => { _.IsEnable = configuration.IsEnable; _.SwaggerRoutePrefix = configuration.SwaggerRoutePrefix; _.SwaggerName = configuration.SwaggerName; _.Url = configuration.Url; _.JsonViewerUrl = configuration.JsonViewerUrl; _.Title = configuration.Title; _.Version = configuration.Version; _.AccessKey = configuration.AccessKey; _.UnAuthorizeMessage = configuration.UnAuthorizeMessage; _.AuthTokenType = configuration.AuthTokenType; _.IsFullSchemaForType = configuration.IsFullSchemaForType; _.AuthorName = configuration.AuthorName; _.AuthorEmail = configuration.AuthorEmail; _.AuthorWebsite = configuration.AuthorWebsite; _.GlobalParameters = configuration.GlobalParameters; _.ExtendOptions = configuration.ExtendOptions; })); }
public static bool IsAccessSwaggerEndpoint(HttpContext httpContext, ElectSwaggerOptions options) { return(httpContext.Request.IsRequestFor(GetSwaggerEndpoint(options, false))); }
public static bool IsAccessJsonViewer(HttpContext httpContext, ElectSwaggerOptions options) { return(httpContext.Request.IsRequestFor(options.JsonViewerUrl)); }
/// <summary> /// Check request access to UI, Json Viewer or Swagger Pure Doc /// </summary> /// <param name="httpContext"></param> /// <param name="options"> </param> /// <returns></returns> public static bool IsAccessSwagger(HttpContext httpContext, ElectSwaggerOptions options) { return(IsAccessUI(httpContext, options) || IsAccessJsonViewer(httpContext, options) || IsAccessSwaggerEndpoint(httpContext, options)); }
public GlobalParameterOperationFilter(IOptions <ElectSwaggerOptions> configuration) { Options = configuration.Value; }
public HomeController(IOptions <ElectSwaggerOptions> electSwaggerConfig) { _electSwaggerOptions = electSwaggerConfig.Value; }
public ElectSwaggerMiddleware(RequestDelegate next, IOptions <ElectSwaggerOptions> configuration) { _next = next; _options = configuration.Value; }
public static IServiceCollection AddElectSwagger(this IServiceCollection services, [NotNull] ElectSwaggerOptions configuration) { return(services.AddElectSwagger(_ => { _.SwaggerRoutePrefix = configuration.SwaggerRoutePrefix; _.SwaggerName = configuration.SwaggerName; _.Url = configuration.Url; _.JsonViewerUrl = configuration.JsonViewerUrl; _.Title = configuration.Title; _.Version = configuration.Version; _.AccessKey = configuration.AccessKey; _.UnAuthorizeMessage = configuration.UnAuthorizeMessage; _.AuthTokenType = configuration.AuthTokenType; _.IsFullSchemaForType = configuration.IsFullSchemaForType; _.IsDescribeAllEnumsAsString = configuration.IsDescribeAllEnumsAsString; _.IsDescribeAllParametersInCamelCase = configuration.IsDescribeAllParametersInCamelCase; _.AuthorName = configuration.AuthorName; _.AuthorEmail = configuration.AuthorEmail; _.AuthorWebsite = configuration.AuthorWebsite; })); }
public static SwaggerGenOptions AddElectSwaggerGenOptions([NotNull] this SwaggerGenOptions swaggerGenOptions, [NotNull] ElectSwaggerOptions configuration) { return(SwaggerGenOptionsHelper.AddElectSwaggerGenOptions(swaggerGenOptions, configuration)); }