From 77cb09e2dd7073f11d38a901895e5d27f4c1e011 Mon Sep 17 00:00:00 2001 From: Haik Date: Sun, 24 Nov 2024 02:06:15 +0400 Subject: [PATCH] code cleanup --- Readme.md | 30 ++++--------------- Shared.Kernel.Demo/appsettings.json | 11 ------- .../OpenApi/Options/ScalarUiConfig.cs | 6 ---- .../OpenApi/Options/SwaggerUiConfig.cs | 7 ----- src/SharedKernel/OpenApi/UiExtensions.cs | 26 ++++------------ src/SharedKernel/SharedKernel.csproj | 2 +- 6 files changed, 12 insertions(+), 70 deletions(-) delete mode 100644 src/SharedKernel/OpenApi/Options/ScalarUiConfig.cs delete mode 100644 src/SharedKernel/OpenApi/Options/SwaggerUiConfig.cs diff --git a/Readme.md b/Readme.md index 04cf399..991e083 100644 --- a/Readme.md +++ b/Readme.md @@ -92,17 +92,6 @@ Follow this example to set up your project with all the features provided by thi "Url": "https://pandatech.it", "Email": "info@pandatech.it" } - }, - "SwaggerUi": { - "InjectedCssPaths": [ - "/assets/css/panda-style.css" - ], - "InjectedJsPaths": [ - "/assets/js/docs.js" - ] - }, - "ScalarUi": { - "FaviconPath": "/assets/images/favicon.svg" } } ``` @@ -186,7 +175,6 @@ of Swashbuckle for generating OpenAPI definitions. Along with this new library, - **Multiple API Documents:** Easily define and organize multiple API documentation groups. - **Enum String Values:** Enum string values are automatically displayed in the documentation, simplifying integration for external partners. -- **Customizable SwaggerUI:** Add custom styles and JavaScript to tailor the UI. - **Security Schemes:** Configure security headers directly in your OpenAPI settings. ### Adding OpenAPI to Your Project @@ -247,17 +235,6 @@ Add the following configuration to your `appsettings.json` file: "Url": "https://pandatech.it", "Email": "info@pandatech.it" } - }, - "SwaggerUi": { - "InjectedCssPaths": [ - "/assets/css/panda-style.css" - ], - "InjectedJsPaths": [ - "/assets/js/docs.js" - ] - }, - "ScalarUi": { - "FaviconPath": "/assets/images/favicon.svg" } } ``` @@ -549,6 +526,7 @@ app.Run(); ## Telemetry Integration Integrate OpenTelemetry for observability, including metrics, traces, and logging: + 1. Setup: ```csharp var builder = WebApplication.CreateBuilder(args); @@ -568,14 +546,16 @@ Integrate OpenTelemetry for observability, including metrics, traces, and loggin - Prometheus exporter ## HealthChecks + - **Startup Validation:** `app.EnsureHealthy()` performs a health check at startup and terminates the application if it is not healthy. - **Endpoints Mapping:** `app.MapHealthCheckEndpoints()` maps default health check endpoints to the application. - **Mapped Endpoints:** - - Ping Endpoint: `url/above-board/ping` - - Health Check Endpoint: `url/above-board/health` + - Ping Endpoint: `url/above-board/ping` + - Health Check Endpoint: `url/above-board/health` Example: + ```csharp var app = builder.Build(); diff --git a/Shared.Kernel.Demo/appsettings.json b/Shared.Kernel.Demo/appsettings.json index cef2011..3522cdc 100644 --- a/Shared.Kernel.Demo/appsettings.json +++ b/Shared.Kernel.Demo/appsettings.json @@ -69,16 +69,5 @@ "Url": "https://pandatech.it", "Email": "info@pandatech.it" } - }, - "SwaggerUi": { - "InjectedCssPaths": [ - "/assets/css/panda-style.css" - ], - "InjectedJsPaths": [ - "/assets/js/docs.js" - ] - }, - "ScalarUi": { - "FaviconPath": "/assets/images/favicon.svg" } } diff --git a/src/SharedKernel/OpenApi/Options/ScalarUiConfig.cs b/src/SharedKernel/OpenApi/Options/ScalarUiConfig.cs deleted file mode 100644 index bd4fb1f..0000000 --- a/src/SharedKernel/OpenApi/Options/ScalarUiConfig.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SharedKernel.OpenApi.Options; - -internal class ScalarUiConfig -{ - public string? FaviconPath { get; set; } -} \ No newline at end of file diff --git a/src/SharedKernel/OpenApi/Options/SwaggerUiConfig.cs b/src/SharedKernel/OpenApi/Options/SwaggerUiConfig.cs deleted file mode 100644 index 77cfc1b..0000000 --- a/src/SharedKernel/OpenApi/Options/SwaggerUiConfig.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SharedKernel.OpenApi.Options; - -internal class SwaggerUiConfig -{ - public string[] InjectedCssPaths { get; set; } = []; - public string[] InjectedJsPaths { get; set; } = []; -} \ No newline at end of file diff --git a/src/SharedKernel/OpenApi/UiExtensions.cs b/src/SharedKernel/OpenApi/UiExtensions.cs index 3b6e78b..9b6632d 100644 --- a/src/SharedKernel/OpenApi/UiExtensions.cs +++ b/src/SharedKernel/OpenApi/UiExtensions.cs @@ -12,10 +12,6 @@ internal static class UiExtensions { internal static WebApplication MapSwaggerUi(this WebApplication app, OpenApiConfig openApiConfigConfiguration) { - var swaggerUiConfig = app.Configuration - .GetSection("SwaggerUi") - .Get(); - app.UseSwaggerUI(options => { foreach (var document in openApiConfigConfiguration.Documents) @@ -24,7 +20,7 @@ internal static WebApplication MapSwaggerUi(this WebApplication app, OpenApiConf } options.RoutePrefix = "swagger"; - options.AddPandaOptions(swaggerUiConfig); + options.AddPandaOptions(); }); @@ -34,7 +30,7 @@ internal static WebApplication MapSwaggerUi(this WebApplication app, OpenApiConf { options.SwaggerEndpoint($"{document.GetEndpointUrl()}", document.Title); options.RoutePrefix = $"doc/{document.GroupName}"; - options.AddPandaOptions(swaggerUiConfig); + options.AddPandaOptions(); }); } @@ -43,17 +39,11 @@ internal static WebApplication MapSwaggerUi(this WebApplication app, OpenApiConf internal static WebApplication MapScalarUi(this WebApplication app) { - var scalarConfig = app.Configuration - .GetSection("ScalarUi") - .Get(); - app.MapScalarApiReference(options => { options.Theme = ScalarTheme.Kepler; - if (scalarConfig?.FaviconPath is not null) - { - options.Favicon = "/swagger-resources/favicon.svg"; - } + + options.Favicon = "/swagger-resources/favicon.svg"; }); return app; } @@ -63,14 +53,10 @@ private static string GetEndpointUrl(this Document document) return $"/openapi/{document.GroupName}.json"; } - private static SwaggerUIOptions AddPandaOptions(this SwaggerUIOptions options, SwaggerUiConfig? swaggerUiConfig) + private static SwaggerUIOptions AddPandaOptions(this SwaggerUIOptions options) { options.DocExpansion(DocExpansion.None); - if (swaggerUiConfig is null) - { - return options; - } - + options.InjectStylesheet("/swagger-resources/panda-style.css"); options.InjectJavascript("/swagger-resources/panda-style.js"); diff --git a/src/SharedKernel/SharedKernel.csproj b/src/SharedKernel/SharedKernel.csproj index 3e8a312..d22dd56 100644 --- a/src/SharedKernel/SharedKernel.csproj +++ b/src/SharedKernel/SharedKernel.csproj @@ -8,7 +8,7 @@ Readme.md Pandatech MIT - 1.0.5 + 1.0.6 Pandatech.SharedKernel Pandatech Shared Kernel Library Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar