namespace AyaNova { using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; using System.Linq; /// /// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter. /// /// This is only required due to bugs in the . /// Once they are fixed and published, this class can be removed. public class SwaggerDefaultValues : IOperationFilter { /// /// Applies the filter to the specified operation using the given context. /// /// The operation to apply the filter to. /// The current operation filter context. 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() ) { 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; } } } }