Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 1d0a66c

Browse files
authored
Merge pull request #1040 from dotnet-architecture/fix/744-swashbukcle-breaking-changes
Remove deprecated Swashbuckle API, refactor
2 parents 8790087 + 91515e7 commit 1d0a66c

File tree

7 files changed

+81
-78
lines changed

7 files changed

+81
-78
lines changed

src/ApiGateways/Mobile.Bff.Shopping/aggregator/Filters/AuthorizeCheckOperationFilter.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ public class AuthorizeCheckOperationFilter : IOperationFilter
1313
public void Apply(Operation operation, OperationFilterContext context)
1414
{
1515
// Check for authorize attribute
16-
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() ||
17-
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any();
16+
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
17+
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1818

19-
if (hasAuthorize)
20-
{
21-
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
22-
operation.Responses.Add("403", new Response { Description = "Forbidden" });
19+
if (!hasAuthorize) return;
20+
21+
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
22+
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
2323

24-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
25-
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
24+
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
2625
{
27-
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator" } }
28-
});
29-
}
26+
new Dictionary<string, IEnumerable<string>>
27+
{
28+
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator" } }
29+
}
30+
};
3031
}
3132
}
3233
}

src/ApiGateways/Web.Bff.Shopping/aggregator/Filters/AuthorizeCheckOperationFilter.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ public class AuthorizeCheckOperationFilter : IOperationFilter
1313
public void Apply(Operation operation, OperationFilterContext context)
1414
{
1515
// Check for authorize attribute
16-
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() ||
17-
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any();
16+
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
17+
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1818

19-
if (hasAuthorize)
20-
{
21-
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
22-
operation.Responses.Add("403", new Response { Description = "Forbidden" });
19+
if (!hasAuthorize) return;
20+
21+
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
22+
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
2323

24-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
25-
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
24+
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
2625
{
27-
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator" } }
28-
});
29-
}
26+
new Dictionary<string, IEnumerable<string>>
27+
{
28+
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator" } }
29+
}
30+
};
3031
}
3132
}
3233
}

src/Services/Basket/Basket.API/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@ public class AuthorizeCheckOperationFilter : IOperationFilter
1111
public void Apply(Operation operation, OperationFilterContext context)
1212
{
1313
// Check for authorize attribute
14-
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() ||
15-
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any();
14+
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
15+
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1616

17-
if (hasAuthorize)
18-
{
19-
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
20-
operation.Responses.Add("403", new Response { Description = "Forbidden" });
17+
if (!hasAuthorize) return;
18+
19+
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
20+
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
2121

22-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
22+
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
23+
{
24+
new Dictionary<string, IEnumerable<string>>
2325
{
24-
new Dictionary<string, IEnumerable<string>>
25-
{
26-
{ "oauth2", new [] { "basketapi" } }
27-
}
28-
};
29-
}
26+
{ "oauth2", new [] { "basketapi" } }
27+
}
28+
};
3029
}
3130
}
3231
}

src/Services/Location/Locations.API/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ internal class AuthorizeCheckOperationFilter : IOperationFilter
1212
public void Apply(Operation operation, OperationFilterContext context)
1313
{
1414
// Check for authorize attribute
15-
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() ||
16-
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any();
15+
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
16+
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1717

18-
if (hasAuthorize)
19-
{
20-
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
21-
operation.Responses.Add("403", new Response { Description = "Forbidden" });
18+
if (!hasAuthorize) return;
19+
20+
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
21+
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
2222

23-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
24-
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
23+
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
24+
{
25+
new Dictionary<string, IEnumerable<string>>
2526
{
2627
{ "oauth2", new [] { "locationsapi" } }
27-
});
28-
}
28+
}
29+
};
2930
}
3031
}
3132
}

src/Services/Marketing/Marketing.API/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@ public class AuthorizeCheckOperationFilter : IOperationFilter
1111
public void Apply(Operation operation, OperationFilterContext context)
1212
{
1313
// Check for authorize attribute
14-
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() ||
15-
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any();
14+
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
15+
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1616

17-
if (hasAuthorize)
18-
{
19-
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
20-
operation.Responses.Add("403", new Response { Description = "Forbidden" });
17+
if (!hasAuthorize) return;
18+
19+
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
20+
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
2121

22-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
22+
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
23+
{
24+
new Dictionary<string, IEnumerable<string>>
2325
{
24-
new Dictionary<string, IEnumerable<string>>
25-
{
26-
{ "oauth2", new [] { "marketingapi" } }
27-
}
28-
};
29-
}
26+
{ "oauth2", new [] { "marketingapi" } }
27+
}
28+
};
3029
}
3130
}
3231
}

src/Services/Ordering/Ordering.API/Infrastructure/Filters/AuthorizeCheckOperationFilter.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ public class AuthorizeCheckOperationFilter : IOperationFilter
1313
public void Apply(Operation operation, OperationFilterContext context)
1414
{
1515
// Check for authorize attribute
16-
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() ||
17-
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any();
16+
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
17+
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1818

19-
if (hasAuthorize)
20-
{
21-
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
22-
operation.Responses.Add("403", new Response { Description = "Forbidden" });
19+
if (!hasAuthorize) return;
20+
21+
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
22+
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
2323

24-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
25-
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
24+
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
25+
{
26+
new Dictionary<string, IEnumerable<string>>
2627
{
2728
{ "oauth2", new [] { "orderingapi" } }
28-
});
29-
}
29+
}
30+
};
3031
}
3132
}
3233
}

src/Services/Webhooks/Webhooks.API/Infrastructure/AuthorizeCheckOperationFilter.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ public class AuthorizeCheckOperationFilter : IOperationFilter
1313
public void Apply(Operation operation, OperationFilterContext context)
1414
{
1515
// Check for authorize attribute
16-
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() ||
17-
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any();
16+
var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
17+
context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
1818

19-
if (hasAuthorize)
20-
{
21-
operation.Responses.Add("401", new Response { Description = "Unauthorized" });
22-
operation.Responses.Add("403", new Response { Description = "Forbidden" });
19+
if (!hasAuthorize) return;
20+
21+
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
22+
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
2323

24-
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
25-
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
24+
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
25+
{
26+
new Dictionary<string, IEnumerable<string>>
2627
{
2728
{ "oauth2", new [] { "webhooksapi" } }
28-
});
29-
}
29+
}
30+
};
3031
}
3132
}
3233
}

0 commit comments

Comments
 (0)