答案比我想象的要容易得多。我最終做的是創建一個IOperationFilter並查找具有特定返回類型的所有操作並將參數添加到它。
class QueryParameterFilter : IOperationFilter
{
void IOperationFilter.Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (apiDescription.ResponseDescription.ResponseType != null && apiDescription.ResponseDescription.ResponseType.Name.Contains("PagedResult"))
{
Dictionary<string, string> parameters = new Dictionary<string, string>()
{
{ "$top", "The max number of records"},
{ "$skip", "The number of records to skip"},
{ "$filter", "A function that must evaluate to true for a record to be returned"},
{ "$select", "Specifies a subset of properties to return"},
{ "$orderby", "Determines what values are used to order a collection of records"}
};
operation.parameters = new List<Parameter>();
foreach (var pair in parameters)
{
operation.parameters.Add(new Parameter
{
name = pair.Key,
required = false,
type = "string",
@in = "query",
description = pair.Value
});
}
}
}
然後他們可以通過owin上下文檢索。
var params = owinContext.Request.Query.ToDictionary(p => p.Key, p => p.Value.FirstOrDefault());