是否可以定制ServiceStack /元的网页? [英] Is it possible to customize the ServiceStack /metadata page?

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

问题描述

我运行一个非标准端口上的负载均衡器后面我的网站。当装载了/元数据页有我的公开的域名还没有该应用程序是托管的本地端口,这会导致链接到不同的格式突破为好。

例如:

有没有一种方法来定制输出这些链接?此外,它是可以定制其他文字/ CSS /网页等,使得它可以被修改,以适应我用我的网站的其余部分的模板?


解决方案

V4更新

V4 ServiceStack提供了许多新的方式来定制内置元数据的网页:

使用虚拟文件系统

ServiceStack的默认虚拟文件系统回落(即在没有物理文件存在)来寻找嵌入的资源文件里面的DLL。

您可以指定数量和precedence其中的装配体,它着眼于与 Config.EmbeddedResourceSources 在默认情况下着眼于:


  • 包含您APPHOST
  • 组装
  • ServiceStack.dll

该VFS现在,您可以完全取代内置ServiceStack元数据页和模板用自己通过简单的复制元数据或 HtmlFormat 模板文件要自定义,并把它们您的文件夹中的:

  /Templates/HtmlFormat.html //自动HtmlFormat模板
/Templates/IndexOperations.html //在/元数据模板
/Templates/OperationControl.html //个体经营模板

上的元数据的网页链接注册

您可以在元数据中的网页与链接添加到您自己的插件

  appHost.GetPlugin< MetadataFeature>()
    .AddPluginLink(昂首阔步-UI /,扬鞭UI);
appHost.GetPlugin< MetadataFeature>()
    .AddDebugLink(调试= requestinfo?,申请信息);

AddPluginLink 添加在插件的链接部分链接,而 AddDebugLink 可以通过使用插件成为唯一调试或开发过程中提供。

使用元数据属性

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

  [API(服务说明)]
[ApiResponse(的HTTPStatus code.BadRequest,您的要求不被理解)]
[ApiResponse(的HTTPStatus code.InternalServerError,哎呀,事情爆发)]
[路线(/招摇/ {}名称,GET,摘要= @GET摘要,说明=GET笔记)
[路线(/招摇/ {}名称,POST,摘要= @POST摘要,说明=注意事项)]
公共类MyRequestDto
{
    [ApiMember(名称=名称,说明=名称描述
               参数类型=路径,数据类型=字符串,IsRequired = TRUE)]
    [ApiAllowableValues​​(名的typeof(彩色))] //枚举
    公共字符串名称{;组; }
}


旧V3注释

ServiceStack 的元数据页面允许通过<有限定制href=\"https://github.com/ServiceStack/ServiceStack/blob/v3/src/ServiceStack/WebHost.Endpoints/EndpointHostConfig.cs\"相对=nofollow> EndpointHostConfig 配置设置(所有ServiceStack配置的生命)。例如。您可以更改主页身体HTML和操作页面的HTML在APPHOST有:

 调用setConfig(新EndpointHostConfig {
    MetadataPageBodyHtml =&LT; P&GT; HTML你想要的主页&LT上; / P&gt;中,
    MetadataOperationPageBodyHtml =&LT; P&GT; HTML,你希望每个操作页面&LT上; / P&gt;中
});

您还可以通过使用归因请求DTO使用[说明]属性作为<一个做进一步增加元数据文件为每个Web服务href=\"https://github.com/ServiceStack/ServiceStack.Examples/blob/master/src/ServiceStack.MovieRest/MovieService.cs#L16\"相对=nofollow> MoviesRest示例项目:

  [说明(GET或删除单个影片凭身份证。POST创造新电影)]
[RestService(/电影,POST,PUT,PATCH,DELETE)]
[RestService(/电影/ {ID})]
公共类电影
{
    公众诠释标识{搞定;组; }
    公共字符串ImdbId {搞定;组; }
    公共字符串名称{搞定;组; }
}

和它是什么样子的MoviesRest /元页

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.

Example:

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 Update

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

Using the Virtual File System

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

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

  • The assembly that contains your AppHost
  • ServiceStack.dll

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");

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

Using Metadata Attributes

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


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>"
});

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

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

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

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