How do I hide routes I don't control from ServiceStack's SwaggerFeature?

﹥>﹥吖頭↗ 提交于 2020-01-14 14:53:28

问题


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

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

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?


回答1:


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 });

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
});


来源:https://stackoverflow.com/questions/40429634/how-do-i-hide-routes-i-dont-control-from-servicestacks-swaggerfeature

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!