advapi
advapi

Reputation: 3907

Have Swagger to substitute servicestack meta

I was wondering if it's possible to have swagger to serve pages at place of SS metadata page... I'm asking this since SS metadata is quite usefull when you've a lot of services

as far I've seen I can remove the feature on SS configuration, disable the httphandler but don't know how to go further

Thanks

Upvotes: 1

Views: 176

Answers (1)

Scott
Scott

Reputation: 21501

So remove the MetaDataFeature in the AppHost Configure method:

SetConfig(new HostConfig { 
    EnableFeatures = Feature.All.Remove(Feature.Metadata)
});

Then create this simple MetaData service, that redirects to Swagger.

[Route("/metadata/{cmds*}", "GET")]
public class RedirectToSwaggerRequest : IReturnVoid 
{
    public string cmds { get; set; }
}

[Restrict(VisibleLocalhostOnly = true)]
public class MetadataService : Service
{
    public void Get(RedirectToSwaggerRequest request)
    {
        base.Response.Redirect("/swagger-ui");
    }
}

Note: {cmds*} in the route above will catch requests for /metadata, /metadata/something & /metadata/somethingelse etc.

Then when a request goes to /metadata then it will redirect to Swagger instead.

Upvotes: 3

Related Questions