C# .net Swashback,签名中没有文档端点查询参数

C# .net Swashback,签名中没有文档端点查询参数,c#,.net,swagger,swashbuckle,C#,.net,Swagger,Swashbuckle,我使用“message”中的查询参数,这些参数可以超过100个,并且是可选的。符号应保持这种形式 所以我的问题是,我如何记录一些查询参数,以在swagger UI中显示,并保持可尝试性 /// <summary> /// Callback Endpoint /// </summary> /// <returns>HTTP 200 <see cref="HttpStatusCode.OK"/>.</returns> /// <par

我使用“message”中的查询参数,这些参数可以超过100个,并且是可选的。符号应保持这种形式

所以我的问题是,我如何记录一些查询参数,以在swagger UI中显示,并保持可尝试性

/// <summary>
/// Callback Endpoint
/// </summary>
/// <returns>HTTP 200 <see cref="HttpStatusCode.OK"/>.</returns>
/// <param name="message">The message</param>
[HttpGet]
[SwaggerParameter("Something", "It is something")]
[Route("endpoint", Name = nameof(Endpoint))]
public virtual async Task<HttpResponseMessage> Endpoint(HttpRequestMessage message)

public类SwaggerParameterAttributeHandler:IOperationFilter
{
public void Apply(操作,SchemaRegistry SchemaRegistry,apisdescription apisdescription)
{
//获取该方法的所有属性
var attributes=apiscription.ActionDescriptor.GetCustomAttributes(true);
if(operation.parameters==null)
{
operation.parameters=新列表();
}
foreach(属性中的var属性)
{
var parameter=operation.parameters.FirstOrDefault(p=>p.name==attribute.name);
if(参数!=null)
{
parameter.required=属性.required;
}
其他的
{
operation.parameters.Add(新参数()
{
name=attribute.name,
description=属性。description,
type=“string”,
required=属性。required
});
}
}
}
}

我得到了一个指示,并且得到了这个问题的解决方案。 我把这篇文章留在这里,也许有人需要它

新参数的问题,需要填写“in”。在大摇大摆的界面上,试用按钮工作得非常好

operation.parameters.Add(new Parameter()
                    {
                        name = attribute.Name,
                        description = attribute.Description,
                        type = "string",
                        required = attribute.Required,
                        @in = "query"
                    });

上面的代码会发生什么情况?在
Apply
方法中创建参数时,可能需要为querystring参数指定位置,即
@in=“query”
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
    public class SwaggerParameterAttribute : Attribute
    {
        public SwaggerParameterAttribute(string name, string description)
        {
            Name = name;
            Description = description;
        }

        public string Name { get; private set; }

        public string Description { get; private set; }

        public bool Required { get; set; } = false;
    }
public class SwaggerParameterAttributeHandler : IOperationFilter
    {
        public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
        {
            // Get all SwaggerParameterAttributes on the method
            var attributes = apiDescription.ActionDescriptor.GetCustomAttributes<SwaggerParameterAttribute>(true);

            if (operation.parameters == null)
            {
                operation.parameters = new List<Parameter>();
            }

            foreach (var attribute in attributes)
            {
                var parameter = operation.parameters.FirstOrDefault(p => p.name == attribute.Name);

                if (parameter != null)
                {
                    parameter.required = attribute.Required;
                }
                else
                {
                    operation.parameters.Add(new Parameter()
                    {
                        name = attribute.Name,
                        description = attribute.Description,
                        type = "string",
                        required = attribute.Required
                    });
                }
            }
        }
    }
operation.parameters.Add(new Parameter()
                    {
                        name = attribute.Name,
                        description = attribute.Description,
                        type = "string",
                        required = attribute.Required,
                        @in = "query"
                    });