如何隐藏不受 ServiceStack 的 SwaggerFeature 控制的路由? [英] How do I hide routes I don't control from ServiceStack's SwaggerFeature?

查看:30
本文介绍了如何隐藏不受 ServiceStack 的 SwaggerFeature 控制的路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的示例中,我使用了 ApiKeyAuthProviderRegistrationFeature,,它们都向我的元数据添加了新路由.

In my example, I'm using the ApiKeyAuthProvider and RegistrationFeature, which both add new routes to my metadata.

我想使用 swagger 作为这些服务的主要文档,但我不希望 /AssignRoles 之类的东西出现在那里.

I want to use swagger as our main documentation for these services, but I don't want things like /AssignRoles showing up there.

我正在探索 OperationFilter,但我很难弄清楚在那里做什么.

I was exploring the OperationFilter, but I'm having a hard time figuring out what to do there.

如何隐藏这些不需要的路由?

What can I do to hide these unwanted routes?

推荐答案

您可以添加 .NET 属性在运行时 以控制您无法使用 ServiceStack 的内置 限制属性,例如要仅允许属性对 localhost 可见,您可以向 AppHost 中的特定请求 DTO 添加限制属性:

You can add .NET Attributes at runtime to control the visibility of services you don't control with ServiceStack's built-in Restriction attributes, e.g. to only allow the attributes to be visible for localhost you can add restriction attributes to the specific Request DTO's in your AppHost:

typeof(AssignRoles)
  .AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
typeof(UnAssignRoles)
  .AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });

要为所有请求隐藏它,您可以将可见性设置为无:

To hide it for all requests you can set the visibility to none:

typeof(AssignRoles)
  .AddAttributes(new RestrictAttribute { VisibilityTo=RequestAttributes.None });
typeof(UnAssignRoles)
  .AddAttributes(new RestrictAttribute { VisibilityTo=RequestAttributes.None });

请注意,当 Debug=true 自动为 Debug 构建启用时,它们仍会在开发模式下显示,要模拟发布构建,您可以将其设置为 false,例如:

Note they'll still be shown in development mode when Debug=true which is automatically enabled for Debug builds, to simulate a release build you can set it to false, e.g:

SetConfig(new HostConfig {
    DebugMode = false
});

这篇关于如何隐藏不受 ServiceStack 的 SwaggerFeature 控制的路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆