Sukram
February 7, 2018, 6:23am
1
I would like to hide certain operations from Swagger, Metadata and OpenAPI Spec e.g show only the POST methods of ServiceStack.Authenticate DTO?
But if i try:
typeof(ServiceStack.Authenticate).AddAttributes(new RestrictAttribute(RequestAttributes.HttpPost))
all HTTP methods will continue to be displayed:
mythz
February 7, 2018, 6:45am
2
The HTTP methods are limited by your Route definition , e.g:
[Route("/myservice", "GET POST")]
But this isn’t possible to annotate for built-in Services which are unspecified and default to allow “ANY” method. So you’ll basically need to modify the Open API schema by removing the HTTP methods you don’t want on selected paths, e.g:
Plugins.Add(new OpenApiFeature
{
ApiDeclarationFilter = api =>
{
foreach (var path in new[] {api.Paths["/auth"], api.Paths["/auth/{provider}"]})
{
path.Get = path.Put = path.Delete = null;
}
},
});
Note: you can also control methods Open API should be included for routes with unspecified verbs with AnyRouteVerbs
, e.g:
Plugins.Add(new OpenApiFeature {
AnyRouteVerbs = new List<string> { HttpMethods.Get, HttpMethods.Post }
})
Which will only generate GET or POST paths for Routes with no methods specified.
Sukram
February 7, 2018, 1:05pm
3
Ok thank you…I will try it out.