问题
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