v4 Update
v4 ServiceStack offers a number of new ways to customize embedded metadata pages:
Using a virtual file system
ServiceStack Virtual FileSystem returns by default (i.e. when there is no physical file) to search for embedded resource files inside the dll.
You can specify the amount and priority with which it looks using Config.EmbeddedResourceSources , which by default looks like this:
- The assembly containing your AppHost
- ServiceStack.dll
Now VFS allows you to completely replace the built-in ServiceStack metadata pages and templates with your own by simply copying the metadata or HtmlFormat template files that you want to configure and placing them in your folder at:
/Templates/HtmlFormat.html // The auto HtmlFormat template /Templates/IndexOperations.html // The /metadata template /Templates/OperationControl.html // Individual operation template
Register links on metadata pages
You can add links to your own plugins on metadata pages using:
appHost.GetPlugin<MetadataFeature>() .AddPluginLink("swagger-ui/", "Swagger UI"); appHost.GetPlugin<MetadataFeature>() .AddDebugLink("?debug=requestinfo", "Request Info");
AddPluginLink adds links in the Plugin Links section, while AddDebugLink can be used by plugins that are available only during debugging or development.
Using metadata attributes
Many of the same attributes used by Swagger are also used on metadata pages, for example:
[Api("Service Description")] [ApiResponse(HttpStatusCode.BadRequest, "Your request was not understood")] [ApiResponse(HttpStatusCode.InternalServerError, "Oops, something broke")] [Route("/swagger/{Name}", "GET", Summary = @"GET Summary", Notes = "GET Notes")] [Route("/swagger/{Name}", "POST", Summary = @"POST Summary", Notes = "Notes")] public class MyRequestDto { [ApiMember(Name="Name", Description = "Name Description", ParameterType = "path", DataType = "string", IsRequired = true)] [ApiAllowableValues("Name", typeof(Color))]
Old notes v3
ServiceStack The metadata page allows you to limit the configuration using EndpointHostConfig (where the entire configuration of ServiceStack is configured). For example. You can change the body HTML and operations page HTML in your AppHost with:
SetConfig(new EndpointHostConfig { MetadataPageBodyHtml = "<p>HTML you want on the home page</p>", MetadataOperationPageBodyHtml = "<p>HTML you want on each operation page</p>" });
You can also add additional metadata documentation for each web service using the Request DTO attribute with the [Description] attribute, as is done in the MoviesRest movie example :
[Description("GET or DELETE a single movie by Id. POST to create new Movies")] [RestService("/movies", "POST,PUT,PATCH,DELETE")] [RestService("/movies/{Id}")] public class Movie { public int Id { get; set; } public string ImdbId { get; set; } public string Title { get; set; } }
And what does it look like on the MoviesRest / metadata page.