From b7e39b59fd0fc7b5610ebff29035bf622079e0d8 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 5 Oct 2022 20:45:21 +0800 Subject: refactor: Change file structure --- .../src/Utilities/SwaggerGenOptionsExtensions.cs | 43 ---------------------- 1 file changed, 43 deletions(-) delete mode 100644 server/src/Utilities/SwaggerGenOptionsExtensions.cs (limited to 'server/src/Utilities/SwaggerGenOptionsExtensions.cs') diff --git a/server/src/Utilities/SwaggerGenOptionsExtensions.cs b/server/src/Utilities/SwaggerGenOptionsExtensions.cs deleted file mode 100644 index a2dcf7a..0000000 --- a/server/src/Utilities/SwaggerGenOptionsExtensions.cs +++ /dev/null @@ -1,43 +0,0 @@ -#nullable enable -using Microsoft.AspNetCore.Mvc.ApiExplorer; -using Microsoft.AspNetCore.Mvc.Controllers; -using Swashbuckle.AspNetCore.SwaggerGen; -using BaseRoute = IOL.GreatOffice.Api.Endpoints.V1.BaseRoute; - -namespace IOL.GreatOffice.Api.Utilities; - -public static class SwaggerGenOptionsExtensions -{ - /// - /// Updates Swagger document to support ApiEndpoints.

- /// For controllers inherited from :
- /// - Replaces action Tag with [namespace]
- ///
- public static void UseApiEndpoints(this SwaggerGenOptions options) { - options.TagActionsBy(EndpointNamespaceOrDefault); - } - - private static IList EndpointNamespaceOrDefault(ApiDescription api) { - if (api.ActionDescriptor is not ControllerActionDescriptor actionDescriptor) { - throw new InvalidOperationException($"Unable to determine tag for endpoint: {api.ActionDescriptor.DisplayName}"); - } - - if (actionDescriptor.ControllerTypeInfo.GetBaseTypesAndThis().Any(t => t == typeof(BaseRoute))) { - return new[] { - actionDescriptor.ControllerTypeInfo.Namespace?.Split('.').Last() - }; - } - - return new[] { - actionDescriptor.ControllerName - }; - } - - public static IEnumerable GetBaseTypesAndThis(this Type type) { - Type? current = type; - while (current != null) { - yield return current; - current = current.BaseType; - } - } -} -- cgit v1.3