Remove deprecated Swashbuckle API, refactor

This commit is contained in:
Miguel Veloso 2019-05-13 18:15:50 +01:00
parent 8790087b85
commit 91515e7ea6
7 changed files with 81 additions and 78 deletions

View File

@ -13,20 +13,21 @@
public void Apply(Operation operation, OperationFilterContext context) public void Apply(Operation operation, OperationFilterContext context)
{ {
// Check for authorize attribute // Check for authorize attribute
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
if (hasAuthorize) if (!hasAuthorize) return;
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
{ {
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); new Dictionary<string, IEnumerable<string>>
operation.Responses.Add("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
{ {
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator" } } { "oauth2", new [] { "Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator" } }
}); }
} };
} }
} }
} }

View File

@ -13,20 +13,21 @@
public void Apply(Operation operation, OperationFilterContext context) public void Apply(Operation operation, OperationFilterContext context)
{ {
// Check for authorize attribute // Check for authorize attribute
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
if (hasAuthorize) if (!hasAuthorize) return;
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
{ {
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); new Dictionary<string, IEnumerable<string>>
operation.Responses.Add("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
{ {
{ "oauth2", new [] { "Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator" } } { "oauth2", new [] { "Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator" } }
}); }
} };
} }
} }
} }

View File

@ -11,13 +11,13 @@ namespace Basket.API.Infrastructure.Filters
public void Apply(Operation operation, OperationFilterContext context) public void Apply(Operation operation, OperationFilterContext context)
{ {
// Check for authorize attribute // Check for authorize attribute
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
if (hasAuthorize) if (!hasAuthorize) return;
{
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.Add("403", new Response { Description = "Forbidden" }); operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>> operation.Security = new List<IDictionary<string, IEnumerable<string>>>
{ {
@ -29,4 +29,3 @@ namespace Basket.API.Infrastructure.Filters
} }
} }
} }
}

View File

@ -12,20 +12,21 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filt
public void Apply(Operation operation, OperationFilterContext context) public void Apply(Operation operation, OperationFilterContext context)
{ {
// Check for authorize attribute // Check for authorize attribute
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
if (hasAuthorize) if (!hasAuthorize) return;
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
{ {
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); new Dictionary<string, IEnumerable<string>>
operation.Responses.Add("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
{ {
{ "oauth2", new [] { "locationsapi" } } { "oauth2", new [] { "locationsapi" } }
}); }
} };
} }
} }
} }

View File

@ -11,13 +11,13 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Filt
public void Apply(Operation operation, OperationFilterContext context) public void Apply(Operation operation, OperationFilterContext context)
{ {
// Check for authorize attribute // Check for authorize attribute
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
if (hasAuthorize) if (!hasAuthorize) return;
{
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.Add("403", new Response { Description = "Forbidden" }); operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>> operation.Security = new List<IDictionary<string, IEnumerable<string>>>
{ {
@ -29,4 +29,3 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure.Filt
} }
} }
} }
}

View File

@ -13,20 +13,21 @@ namespace Ordering.API.Infrastructure.Filters
public void Apply(Operation operation, OperationFilterContext context) public void Apply(Operation operation, OperationFilterContext context)
{ {
// Check for authorize attribute // Check for authorize attribute
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
if (hasAuthorize) if (!hasAuthorize) return;
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
{ {
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); new Dictionary<string, IEnumerable<string>>
operation.Responses.Add("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
{ {
{ "oauth2", new [] { "orderingapi" } } { "oauth2", new [] { "orderingapi" } }
}); }
} };
} }
} }
} }

View File

@ -13,20 +13,21 @@ namespace Webhooks.API.Infrastructure
public void Apply(Operation operation, OperationFilterContext context) public void Apply(Operation operation, OperationFilterContext context)
{ {
// Check for authorize attribute // Check for authorize attribute
var hasAuthorize = context.ApiDescription.ControllerAttributes().OfType<AuthorizeAttribute>().Any() || var hasAuthorize = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any() ||
context.ApiDescription.ActionAttributes().OfType<AuthorizeAttribute>().Any(); context.MethodInfo.GetCustomAttributes(true).OfType<AuthorizeAttribute>().Any();
if (hasAuthorize) if (!hasAuthorize) return;
operation.Responses.TryAdd("401", new Response { Description = "Unauthorized" });
operation.Responses.TryAdd("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>
{ {
operation.Responses.Add("401", new Response { Description = "Unauthorized" }); new Dictionary<string, IEnumerable<string>>
operation.Responses.Add("403", new Response { Description = "Forbidden" });
operation.Security = new List<IDictionary<string, IEnumerable<string>>>();
operation.Security.Add(new Dictionary<string, IEnumerable<string>>
{ {
{ "oauth2", new [] { "webhooksapi" } } { "oauth2", new [] { "webhooksapi" } }
}); }
} };
} }
} }
} }