コード例 #1
0
        public void Apply(Swashbuckle.AspNetCore.Swagger.Operation operation,
                          Swashbuckle.AspNetCore.SwaggerGen.OperationFilterContext context)
        {
            if (operation.Parameters == null)
            {
                return;
            }

            foreach (var parameter in operation.Parameters.OfType <Swashbuckle.AspNetCore.Swagger.NonBodyParameter>())
            {
                Microsoft.AspNetCore.Mvc.ApiExplorer.ApiParameterDescription description =
                    context
                    .ApiDescription
                    .ParameterDescriptions
                    .FirstOrDefault(p => p.Name == parameter.Name);

                if (description == null)
                {
                    continue;
                }

                Microsoft.AspNetCore.Mvc.ApiExplorer.ApiParameterRouteInfo 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;
            }
        }
コード例 #2
0
 private static bool IsOrderableAndSortParameter(Microsoft.AspNetCore.Mvc.ApiExplorer.ApiParameterDescription param)
 {
     return(param?.ModelMetadata?.ContainerType != null &&
            typeof(IOrderable).IsAssignableFrom(param.ModelMetadata.ContainerType) &&
            param.Name == nameof(IOrderable.Sort));
 }