是否可以自定义 ServiceStack/metadata 页面? [英] Is it possible to customize the ServiceStack /metadata page?

查看:26
本文介绍了是否可以自定义 ServiceStack/metadata 页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在非标准端口上的负载均衡器后面运行我的站点.加载/metadata 页面时,它具有我的公共域名,但具有托管应用程序的本地端口,这也会导致指向不同格式的链接中断.

I run my site behind a loadbalancer on a non-standard port. When loading up the /metadata page it has my public domain name yet the local port that the app is hosted on, which causes the links to the different formats to break as well.

示例:

有没有办法在输出中自定义这些链接?此外,是否可以自定义页面的其他文本/css/等,以便可以对其进行修改以适应我用于网站其余部分的模板?

Is there a way to customize these links in the output? Further, is it possible to customize the other text/css/etc of the page, such that it can be modified to fit into the template I use for the rest of my site?

推荐答案

v4 更新

v4 ServiceStack 提供了许多自定义内置元数据页面的新方法:

v4 Update

v4 ServiceStack provides a number of new ways to customize the built-in Metadata pages:

ServiceStack 的虚拟文件系统默认回退(即当不存在物理文件时)寻找 dll 中的嵌入式资源文件.

ServiceStack's Virtual FileSystem by default falls back (i.e when no physical file exists) to looking for Embedded Resource Files inside dlls.

您可以使用默认查看的 Config.EmbeddedResourceSources 指定它查看的程序集的数量和优先级:

You can specify the number and precedence of which Assemblies it looks at with Config.EmbeddedResourceSources which by default looks at:

  • 包含您的 AppHost 的程序集
  • ServiceStack.dll

VFS 现在让您只需复制您想要自定义的元数据或 HtmlFormat 模板文件并将它们放置在您的文件夹中,即可用您自己的完全替换内置 ServiceStack 元数据页面和模板:

The VFS now lets you completely replace built-in ServiceStack metadata pages and templates with your own by simply copying the metadata or HtmlFormat Template files you want to customize 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

在元数据页面上注册链接

您可以在元数据页面中添加指向您自己插件的链接:

Registering links on the Metadata pages

You can add links to your own Plugins in the metadata pages with:

appHost.GetPlugin<MetadataFeature>()
    .AddPluginLink("swagger-ui/", "Swagger UI");
appHost.GetPlugin<MetadataFeature>()
    .AddDebugLink("?debug=requestinfo", "Request Info");

AddPluginLinkPlugin Links 部分下添加链接,而 AddDebugLink 只能由仅在调试或开发期间可用的插件使用.

AddPluginLink adds links under the Plugin Links section whilst AddDebugLink can be used by plugins only available during debugging or development.

Swagger 中使用的许多相同属性也是在元数据页面中使用,例如:

Many of the same attributes used in Swagger are also used in the metadata pages, e.g:

[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))] //Enum
    public string Name { get; set; }
}

<小时>

较旧的 v3 注释

ServiceStack 的元数据页面允许通过 EndpointHostConfig 配置设置(所有 ServiceStack 配置所在的位置).例如.您可以使用以下命令更改 AppHost 中的主页正文 HTML 和操作页面 HTML:


Older v3 Notes

ServiceStack's Metadata page allows limited customization via the EndpointHostConfig config settings (where all of ServiceStack configuration lives). E.g. you can change the Home page Body HTML and the 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>"
});

您还可以通过使用带有 [Description] 属性的请求 DTO 来为每个 Web 服务添加更多元数据文档,如MoviesRest 示例项目:

You can also add further metadata documentation for each Web Service by using the attributing the Request DTO with the [Description] attribute as done in the MoviesRest Example project:

[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; }
}

以及它在 MoviesRest /metadata 页面上的样子.

And what it looks like on the MoviesRest /metadata page.

这篇关于是否可以自定义 ServiceStack/metadata 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆