Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 607
IronicMuffin Avatar asked Dec 13 '25 02:12

IronicMuffin


1 Answers

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
});
like image 50
mythz Avatar answered Dec 16 '25 13:12

mythz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!