您需要将 Swagger.NET 集成到您的项目中,以便最终得到以下控制器:
public class SwaggerController : ApiController { /* snip */ }
您还应该注册以下路线:
context.Routes.MapHttpRoute (
name : "Swagger",
routeTemplate: "api/swagger"
defaults: new
{
controller = "Swagger",
action = "Get",
});
假设这正在工作,您应该能够调用 /api/swagger 并获得如下内容:
{
apiVersion: "4.0.0.0",
swaggerVersion: "2.0",
basePath: "http://localhost:5555",
resourcePath: null,
apis: [
{
path: "/api/docs/Values",
description: "No Documentation Found.",
operations: [ ]
},
{
path: "/api/docs/Home",
description: "No Documentation Found.",
operations: [ ]
}
]
}
然后在 SwaggerUI/index.html 你会想要更新discoveryUrl:
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl: "http://localhost:5555/api/swagger",
apiKey:"",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put']
});
window.swaggerUi.load();
});
</script>