我正在使用我的Web API使用Swashbuckle(swagger for C#).我有几个返回列表的GET端点,我允许用户在QueryString中添加perpage和page params
示例:http://myapi.com/endpoint/?page = 5&eachpage = 10
我看到swagger确实支持'query'中的参数但是我如何让Swashbuckle去做呢?
我在其中一条评论中提到我通过创建自定义属性来解决我的问题,以便让我做我需要的事情.以下是我的解决方案的代码:
[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 Type DataType { get; set; }
public string ParameterType { get; set; }
public string Description { get; private set; }
public bool Required { get; set; } = false; …Run Code Online (Sandbox Code Playgroud)