在我的示例中,我使用了 ApiKeyAuthProvider
和 RegistrationFeature
,它们都将新路由添加到我的元数据。
我想使用 swagger 作为这些服务的主要文档,但我不希望像 /AssignRoles
这样的东西出现在那里。
我正在探索 OperationFilter,但我很难弄清楚在那里做什么。
如何隐藏这些不需要的路由?
最佳答案
您可以添加 .NET Attributes at runtime使用 ServiceStack 的内置 Restriction attributes 控制您无法控制的服务的可见性,例如只允许属性对本地主机可见,您可以将限制属性添加到 AppHost 中的特定请求 DTO:
typeof(AssignRoles)
.AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
typeof(UnAssignRoles)
.AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
要为所有请求隐藏它,您可以将可见性设置为无:
typeof(AssignRoles)
.AddAttributes(new RestrictAttribute { VisibilityTo=RequestAttributes.None });
typeof(UnAssignRoles)
.AddAttributes(new RestrictAttribute { VisibilityTo=RequestAttributes.None });
请注意,当 Debug=true
自动为 Debug 构建启用时,它们仍会在开发模式下显示,要模拟发布构建,您可以将其设置为 false ,例如:
SetConfig(new HostConfig {
DebugMode = false
});
关于servicestack - 如何隐藏不受 ServiceStack 的 SwaggerFeature 控制的路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40429634/