Reputation: 123
The ServiceStack.Api.Swagger defines 2 endpoints
These are used by swagger-ui in order to display rest documentation. How can I hide them from showing up in the standard metadata page of servicestack? I cannot decorate them with the [Restrict] attribute because they are defined internally within the ServiceStack.Api.Swagger dll.
Regards
Dirk
Upvotes: 2
Views: 2047
Reputation: 143284
You can use the new v4 feature of adding .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(Resources)
.AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
typeof(ResourceRequest)
.AddAttributes(new RestrictAttribute { VisibleLocalhostOnly = true });
To hide it for all requests you can set the visibility to none:
typeof(Resources)
.AddAttributes(new RestrictAttribute { VisibilityTo=RequestAttributes.None });
typeof(ResourceRequest)
.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
});
Upvotes: 3