如何隐藏不受 ServiceStack 的 SwaggerFeature 控制的路由?
How do I hide routes I don't control from ServiceStack's SwaggerFeature?
在我的示例中,我使用了 ApiKeyAuthProvider
和 RegistrationFeature,
,它们都将新路由添加到我的元数据中。
我想使用 swagger 作为这些服务的主要文档,但我不希望 /AssignRoles
之类的东西出现在那里。
我正在探索 OperationFilter,但我很难弄清楚在那里做什么。
如何隐藏这些不需要的路由?
您可以添加 .NET Attributes at runtime to control the visibility of services you don't control with ServiceStack's built-in Restriction attributes,例如仅允许属性对本地主机可见,您可以将限制属性添加到 AppHost 中的特定请求 DTO:
typeof(AssignRoles)
.AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
typeof(UnAssignRoles)
.AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
要为所有请求隐藏它,您可以将可见性设置为 none:
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
});
在我的示例中,我使用了 ApiKeyAuthProvider
和 RegistrationFeature,
,它们都将新路由添加到我的元数据中。
我想使用 swagger 作为这些服务的主要文档,但我不希望 /AssignRoles
之类的东西出现在那里。
我正在探索 OperationFilter,但我很难弄清楚在那里做什么。
如何隐藏这些不需要的路由?
您可以添加 .NET Attributes at runtime to control the visibility of services you don't control with ServiceStack's built-in Restriction attributes,例如仅允许属性对本地主机可见,您可以将限制属性添加到 AppHost 中的特定请求 DTO:
typeof(AssignRoles)
.AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
typeof(UnAssignRoles)
.AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
要为所有请求隐藏它,您可以将可见性设置为 none:
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
});