Ok, everything seems to be working except for the api explorer so now can turn back to that. (api explorer issues are caused by the api versioning system as removing it fixes the missing api explorer routes

This commit is contained in:
2019-10-17 18:42:28 +00:00
parent c9155ff24e
commit 0d42f163fc
27 changed files with 285 additions and 375 deletions

View File

@@ -1,69 +1,47 @@
namespace AyaNova
{
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
//https://github.com/domaindrivendev/Swashbuckle.AspNetCore/releases/tag/v5.0.0-rc3
/// <summary>
/// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter.
/// </summary>
/// <remarks>This <see cref="IOperationFilter"/> is only required due to bugs in the <see cref="SwaggerGenerator"/>.
/// Once they are fixed and published, this class can be removed.</remarks>
public class SwaggerDefaultValues : IOperationFilter
{
/// <summary>
/// Applies the filter to the specified operation using the given context.
/// </summary>
/// <param name="operation">The operation to apply the filter to.</param>
/// <param name="context">The current operation filter context.</param>
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
// REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/412
// REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/413
foreach (var parameter in operation.Parameters)
{
var description = context.ApiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);
var routeInfo = description.RouteInfo;
if (parameter.Description == null)
{
parameter.Description = description.ModelMetadata?.Description;
}
if (routeInfo == null)
{
continue;
}
// if (parameter.Default == null)
// {
// parameter.Default = routeInfo.DefaultValue;
// }
parameter.Required |= !routeInfo.IsOptional;
}
}
}
// namespace AyaNova
// {
// using Swashbuckle.AspNetCore.SwaggerGen;
// using System.Linq;
// /// <summary>
// /// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter.
// /// </summary>
// /// <remarks>This <see cref="IOperationFilter"/> is only required due to bugs in the <see cref="SwaggerGenerator"/>.
// /// Once they are fixed and published, this class can be removed.</remarks>
// public class SwaggerDefaultValues : IOperationFilter
// {
// /// <summary>
// /// Applies the filter to the specified operation using the given context.
// /// </summary>
// /// <param name="operation">The operation to apply the filter to.</param>
// /// <param name="context">The current operation filter context.</param>
// public void Apply( Operation operation, OperationFilterContext context )
// {
// // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/412
// // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/413
// foreach ( var parameter in operation.Parameters.OfType<NonBodyParameter>() )
// {
// var description = context.ApiDescription.ParameterDescriptions.First( p => p.Name == parameter.Name );
// var routeInfo = description.RouteInfo;
// if ( parameter.Description == null )
// {
// parameter.Description = description.ModelMetadata?.Description;
// }
// AuthResponsesOperationFilter.cs
public class AuthResponsesOperationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
var authAttributes = context.MethodInfo.DeclaringType.GetCustomAttributes(true)
.Union(context.MethodInfo.GetCustomAttributes(true))
.OfType<AuthorizeAttribute>();
// if ( routeInfo == null )
// {
// continue;
// }
if (authAttributes.Any())
operation.Responses.Add("401", new OpenApiResponse { Description = "Unauthorized" });
}
}
}
// if ( parameter.Default == null )
// {
// parameter.Default = routeInfo.DefaultValue;
// }
// parameter.Required |= !routeInfo.IsOptional;
// }
// }
// }
// }