我使用Servicestack版本4.0.52.0及ServiceStack.Api.Swagger 4.0.0.0ServiceStack.Api.Swagger SwaggerResourcesService排除路由與路由配置begining
我在serviceStack應用主機定義的可變參數的路由的所有路由導出類(AppHostBase):配置方法
public class AppHost : AppHostBase
{
public override void Configure(Funq.Container container)
{
//Infrastructure code goes here
....
//Add routes
Routes.Add<TestRequestDTO>("/{MyApplicationKey}/TestOperation/", "GET")
}
}
雖然這些航線在ServiceStack元數據頁可見,招搖UI不顯示路線與MyApplicationKey begining;更仔細地分析我們的代碼庫中發現ServiceStack.Api.Swagger.SwaggerResourcesService.Get方法問題:
[AddHeader(DefaultContentType = MimeTypes.Json)]
[DefaultRequest(typeof(SwaggerResources))]
[Restrict(VisibilityTo = RequestAttributes.None)]
public class SwaggerResourcesService : Service
{
private readonly Regex resourcePathCleanerRegex = new Regex(@"/[^\/\{]*", RegexOptions.Compiled);
internal static Regex resourceFilterRegex;
internal static Action<SwaggerResourcesResponse> ResourcesResponseFilter { get; set; }
internal const string RESOURCE_PATH = "/resource";
public object Get(SwaggerResources request)
{
var basePath = base.Request.GetBaseUrl();
var result = new SwaggerResourcesResponse
{
BasePath = basePath,
Apis = new List<SwaggerResourceRef>(),
ApiVersion = HostContext.Config.ApiVersion,
Info = new SwaggerInfo
{
Title = HostContext.ServiceName,
}
};
var operations = HostContext.Metadata;
var allTypes = operations.GetAllOperationTypes();
var allOperationNames = operations.GetAllOperationNames();
foreach (var operationName in allOperationNames)
{
if (resourceFilterRegex != null && !resourceFilterRegex.IsMatch(operationName)) continue;
var name = operationName;
var operationType = allTypes.FirstOrDefault(x => x.Name == name);
if (operationType == null) continue;
if (operationType == typeof(SwaggerResources) || operationType == typeof(SwaggerResource))
continue;
if (!operations.IsVisible(Request, Format.Json, operationName)) continue;
CreateRestPaths(result.Apis, operationType, operationName);
}
result.Apis = result.Apis.OrderBy(a => a.Path).ToList();
if (ResourcesResponseFilter != null)
ResourcesResponseFilter(result);
return new HttpResult(result) {
ResultScope =() => JsConfig.With(includeNullValues:false)
};
}
protected void CreateRestPaths(List<SwaggerResourceRef> apis, Type operationType, string operationName)
{
var map = HostContext.ServiceController.RestPathMap;
var feature = HostContext.GetPlugin<SwaggerFeature>();
var paths = new List<string>();
foreach (var key in map.Keys)
{
paths.AddRange(map[key].Where(x => x.RequestType == operationType).Select(t => **resourcePathCleanerRegex.Match**(t.Path).Value));
}
......
}
對我們如何才能解決這個問題的任何提示?在進行資源清單時,是否有任何方法可將MyApplicationKey的值告訴Swagger API?
您可以隨時發送拉取請求。 – mythz