From a3d1193ce9546cde4e15e39c6f4af27cb577a996 Mon Sep 17 00:00:00 2001 From: Chebotov Nikolay Date: Tue, 28 Jul 2020 23:28:30 +0300 Subject: [PATCH] Fix #12 --- CHANGELOG.md | 5 +++++ .../Extensions/EnumTypeExtensions.cs | 2 +- .../Factories/ApiDescriptionFactory.cs | 4 ++-- .../Filters/HidePathsAndDefinitionsByRolesDocumentFilter.cs | 4 ++-- .../Unchase.Swashbuckle.AspNetCore.Extensions.csproj | 6 +++--- test/WebApi3.1-Swashbuckle/WebApi3.1-Swashbuckle.csproj | 4 ++-- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba8aa7..42529c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ These are the changes to each version that has been released on the [nuget](https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions/). +## v2.3.9 `(2020-07-11)` + +- [x] Update nuget dependencies for sample WebAPI +- [x] Fix [issue #12](https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/issues/12) + ## v2.3.8 `(2020-07-06)` - [x] Fix bug with missed required definitions in `HidePathsAndDefinitionsByRolesDocumentFilter` diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Extensions/EnumTypeExtensions.cs b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Extensions/EnumTypeExtensions.cs index ea8ec5d..e9cf98f 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Extensions/EnumTypeExtensions.cs +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Extensions/EnumTypeExtensions.cs @@ -44,7 +44,7 @@ private static string GetFieldAttributeDescription(this Type enumType, object en if (!enumType.IsEnum) return string.Empty; var memInfo = enumType.GetMember(enumField.ToString()); - var attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); + var attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), true); if (attributes.Length > 0) return (attributes[attributeNumber] as DescriptionAttribute)?.Description ?? string.Empty; return string.Empty; diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Factories/ApiDescriptionFactory.cs b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Factories/ApiDescriptionFactory.cs index bb92168..a3f1f0c 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Factories/ApiDescriptionFactory.cs +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Factories/ApiDescriptionFactory.cs @@ -44,7 +44,7 @@ internal static ApiDescription Create( var actionDescriptor = CreateActionDescriptor(methodInfo); - var routAttr = controllerType.GetCustomAttributes().OfType().LastOrDefault(); + var routAttr = controllerType.GetCustomAttributes(true).OfType().LastOrDefault(); if (string.IsNullOrWhiteSpace(actionDescriptor?.AttributeRouteInfo?.Template)) return null; @@ -62,7 +62,7 @@ internal static ApiDescription Create( actionDescriptor.AttributeRouteInfo.Template.Replace($"[{routeValue.Key}]", routeValue.Value); } - httpMethod = httpMethod ?? methodInfo?.GetCustomAttributes().OfType().FirstOrDefault()?.HttpMethods?.FirstOrDefault(); + httpMethod = httpMethod ?? methodInfo?.GetCustomAttributes(true).OfType().FirstOrDefault()?.HttpMethods?.FirstOrDefault(); var apiDescription = new ApiDescription { diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/HidePathsAndDefinitionsByRolesDocumentFilter.cs b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/HidePathsAndDefinitionsByRolesDocumentFilter.cs index 8e3293b..0dfb690 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/HidePathsAndDefinitionsByRolesDocumentFilter.cs +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/HidePathsAndDefinitionsByRolesDocumentFilter.cs @@ -169,7 +169,7 @@ internal static void RemovePathsAndComponents( foreach (var path in paths) { - var authorizeAttributes = path.Key.ActionMethodInfo.GetCustomAttributes(false); + var authorizeAttributes = path.Key.ActionMethodInfo.GetCustomAttributes(true); foreach (var authorizeAttribute in authorizeAttributes) { var authorizeAttributeRoles = authorizeAttribute?.Roles?.Split(',').Select(r => r.Trim()).ToList(); @@ -180,7 +180,7 @@ internal static void RemovePathsAndComponents( } } - var controllerAuthorizeAttributes = path.Key.ControllerType.GetCustomAttributes(false); + var controllerAuthorizeAttributes = path.Key.ControllerType.GetCustomAttributes(true); foreach (var controllerAuthorizeAttribute in controllerAuthorizeAttributes) { var authorizeAttributeRoles = controllerAuthorizeAttribute?.Roles?.Split(',').Select(r => r.Trim()).ToList(); diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj index 7aebcc2..2450f87 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj @@ -14,9 +14,9 @@ 7.3 https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/blob/master/assets/icon.png?raw=true - 2.3.8 - 2.3.8.0 - 2.3.8.0 + 2.3.9 + 2.3.9.0 + 2.3.9.0 false Unchase.Swashbuckle.AspNetCore.Extensions.xml diff --git a/test/WebApi3.1-Swashbuckle/WebApi3.1-Swashbuckle.csproj b/test/WebApi3.1-Swashbuckle/WebApi3.1-Swashbuckle.csproj index 76301f8..3a602ed 100644 --- a/test/WebApi3.1-Swashbuckle/WebApi3.1-Swashbuckle.csproj +++ b/test/WebApi3.1-Swashbuckle/WebApi3.1-Swashbuckle.csproj @@ -14,8 +14,8 @@ - - + +