1

我可能会因为问这个问题而被击落:

我想将我的 API 中的端点标记为“新”或“更新”,这样当开发人员查看我的招摇 UI 时,他们可以看到所有最近添加的内容。

这样的事情存在吗?

4

1 回答 1

1

这在核心 Swagger-UI 功能或 ServiceStack 的 Swagger 支持中不存在。

但是,您可以毫不费力地自己滚动。诀窍是支持原始 HTML的SummaryNotes属性。RouteAttribute

像这样装饰你的 DTO:

static class Docs {
    public const string NewApi = @"<em class=""new-api"">New!</em> ";
}

[Route(...., Notes = Docs.NewApi + "Detailed description of DTO goes here")]
public class MyDto {  ...  }

// OR

[Route(...., Summary = Docs.NewApi + "Summary goes here")]
public class MyDto {  ...  }

然后你可以在你的 swagger-ui index.html 中添加一些 CSS:

.new-api {
    background-color: #ffff00;
    font-weight: bold;
    font-style: normal;
}

现在,您只需将该字符串常量附加到相应 Route 属性上的NotesorSummary属性,它就会在 Swagger UI 上显示为样式标记。当然,您需要在更改 DTO 时手动添加/删除这些标记,但实现起来非常简单。

于 2014-03-07T14:59:41.373 回答