Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq;
- using Swashbuckle.AspNetCore.Swagger;
- using Swashbuckle.AspNetCore.SwaggerGen;
- namespace Infrastructure.Web.Mvc.Swagger.Filters
- {
- public class SwaggerDefaultValues : IOperationFilter
- {
- public void Apply(Operation operation, OperationFilterContext context)
- {
- if (operation.Parameters == null) return;
- 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;
- if (routeInfo == null) continue;
- if (parameter.Default == null) parameter.Default = routeInfo.DefaultValue;
- parameter.Required |= !routeInfo.IsOptional;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement