Exemple #1
0
 public void Apply(Operation operation, Swashbuckle.AspNetCore.SwaggerGen.OperationFilterContext context)
 {
     ActionAttributes     = context.MethodInfo.GetCustomAttributes(true).OfType <Attribute>();
     ControllerAttributes = context.MethodInfo.DeclaringType.GetCustomAttributes(true).OfType <Attribute>();
     CombinedAttributes   = ActionAttributes.Union(ControllerAttributes);
     ConfigureResponses(operation, context);
     ExcludeSwaggerResonse(operation);
 }
 public void Apply(Operation operation, Swashbuckle.AspNetCore.SwaggerGen.OperationFilterContext context)
 {
     ActionAttributes     = context.ApiDescription.ActionAttributes().OfType <Attribute>();
     ControllerAttributes = context.ApiDescription.ActionAttributes().OfType <Attribute>();
     CombinedAttributes   = ActionAttributes.Union(ControllerAttributes);
     ConfigureResponses(operation, context);
     ExcludeSwaggerResonse(operation);
 }
Exemple #3
0
        public void Apply(Swashbuckle.AspNetCore.Swagger.Operation operation,
                          Swashbuckle.AspNetCore.SwaggerGen.OperationFilterContext context)
        {
            if (operation.Parameters == null)
            {
                operation.Parameters = new List <Swashbuckle.AspNetCore.Swagger.IParameter>();
            }

            operation.Parameters.Add(new Swashbuckle.AspNetCore.Swagger.NonBodyParameter
            {
                Name     = "CompanyId",
                In       = "header",
                Type     = "string",
                Required = true
            });
        }
Exemple #4
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;
            }
        }
        private static void ApplyParamComments(Operation operation, XPathNavigator methodNode, OperationFilterContext context)
        {
            if (operation.Parameters == null)
            {
                return;
            }

            foreach (var parameter in operation.Parameters)
            {
                // Inspect context to find the corresponding action parameter
                // NOTE: If a parameter binding is present (e.g. [FromQuery(Name..)]), then the lookup needs
                // to be against the "bound" name and not the actual parameter name
                var actionParameter = context.ApiDescription.ActionDescriptor
                                      .Parameters
                                      .FirstOrDefault(paramDesc =>
                                                      (paramDesc.BindingInfo != null && paramDesc.BindingInfo.BinderModelName == parameter.Name) ||
                                                      paramDesc.Name == parameter.Name
                                                      );
                if (actionParameter == null)
                {
                    continue;
                }

                var paramNode = methodNode.SelectSingleNode(string.Format(ParamXPath, actionParameter.Name));
                if (paramNode != null)
                {
                    parameter.Description = XmlCommentsTextHelper.Humanize(paramNode.InnerXml);
                }
            }
        }
Exemple #6
0
 protected abstract void ConfigureResponses(Operation operation, Swashbuckle.AspNetCore.SwaggerGen.OperationFilterContext context);
Exemple #7
0
 public void Apply(Operation operation, OperationFilterContext context)
 {
     ApplyOperationAttributes(operation, context);
     ApplyOperationFilterAttributes(operation, context);
 }