public static IApplicationBuilder UseReDoc( this IApplicationBuilder app, Action <ReDocOptions> setupAction) { var options = new ReDocOptions(); setupAction?.Invoke(options); app .UseMiddleware <ReDocIndexMiddleware>(options) .UseFileServer(new FileServerOptions { EnableDefaultFiles = true, EnableDirectoryBrowsing = true, DefaultFilesOptions = { DefaultFileNames = new List <string> { "api-documentation.html" } }, RequestPath = string.IsNullOrEmpty(options.RoutePrefix) ? string.Empty : $"/{options.RoutePrefix}", FileProvider = new EmbeddedFileProvider(typeof(ReDocBuilderExtensions).GetTypeInfo().Assembly, EmbeddedFilesNamespace), }); return(app); }
/// <summary> /// Injects additional CSS stylesheets into the index.html page /// </summary> /// <param name="options"></param> /// <param name="path">A path to the stylesheet - i.e. the link "href" attribute</param> /// <param name="media">The target media - i.e. the link "media" attribute</param> public static void InjectStylesheet(this ReDocOptions options, string path, string media = "screen") { var builder = new StringBuilder(options.HeadContent); builder.AppendLine($"<link href='{path}' rel='stylesheet' media='{media}' type='text/css' />"); options.HeadContent = builder.ToString(); }
public ReDocIndexMiddleware(RequestDelegate next, ReDocOptions options) { _next = next; _options = options; }
public static IApplicationBuilder UseSwaggerDocumentation( this IApplicationBuilder app, SwaggerDocumentationOptions options) { // A bit of a hack to give all the Funcs the default value, but still managing them in one place. var defaultValues = new ReDocOptions(); if (options.ApiVersionDescriptionProvider == null) { throw new ArgumentNullException(nameof(options.ApiVersionDescriptionProvider)); } if (options.DocumentTitleFunc == null) { options.DocumentTitleFunc = _ => defaultValues.DocumentTitle; } if (options.DocumentDescriptionFunc == null) { options.DocumentDescriptionFunc = _ => defaultValues.DocumentDescription; } if (options.ApplicationNameFunc == null) { options.ApplicationNameFunc = _ => defaultValues.ApplicationName; } if (options.HeaderTitleFunc == null) { options.HeaderTitleFunc = _ => defaultValues.HeaderTitle; } if (options.HeaderLinkFunc == null) { options.HeaderLinkFunc = _ => defaultValues.HeaderLink; } if (options.HeadContentFunc == null) { options.HeadContentFunc = _ => defaultValues.HeadContent; } if (string.IsNullOrWhiteSpace(options.FooterVersion)) { options.FooterVersion = defaultValues.FooterVersion; } if (string.IsNullOrWhiteSpace(options.CSharpClient.ClassName)) { throw new ArgumentNullException(nameof(options.CSharpClient.ClassName)); } if (string.IsNullOrWhiteSpace(options.CSharpClient.Namespace)) { throw new ArgumentNullException(nameof(options.CSharpClient.Namespace)); } if (string.IsNullOrWhiteSpace(options.TypeScriptClient.ClassName)) { throw new ArgumentNullException(nameof(options.TypeScriptClient.ClassName)); } app .MapDocs(options) .MapClient(options, "csharp", GenerateCSharpCode) .MapClient(options, "jquery", GeneratejQueryCode) .MapClient(options, "angular", GenerateAngularCode) .MapClient(options, "angularjs", GenerateAngularJsCode); return(app); }