Permalink
Browse files

Added support for ApiExplorer

  • Loading branch information...
1 parent 63645d5 commit 79cac08865bd97bc63fd730d2f1d16de419a7500 @davidsavagejr committed Oct 10, 2012
Oops, something went wrong.
@@ -2,8 +2,16 @@
using System.Web.Http;
public sealed class HelloController : ApiController {
+ /// <summary>
+ /// Gets this instance.
+ /// </summary>
+ /// <returns></returns>
public Message Get() {
return new Message("Hello World from API version 1!", "Hello World");
}
+ public void Delete(string messageId)
+ {
+ // this should show up as a delete.
+ }
}
}
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Mvc;
+using VersioningTestApp.Models;
+using System.Web.Http;
+using SDammann.WebApi.Versioning;
+
+namespace VersioningTestApp.Controllers
+{
+ public class HomeController : Controller
+ {
+ public ActionResult Index()
+ {
+ return View(new DocumentationModel(new VersionedApiExplorer(GlobalConfiguration.Configuration)));
+ }
+
+ }
+}
@@ -1,6 +1,7 @@
namespace VersioningTestApp {
using System.Web;
using System.Web.Http;
+ using System.Web.Http.Description;
using System.Web.Http.Dispatcher;
using System.Web.Mvc;
using System.Web.Routing;
@@ -17,8 +18,7 @@ public class WebApiApplication : HttpApplication {
RouteConfig.RegisterRoutes(RouteTable.Routes);
// enable API versioning
- GlobalConfiguration.Configuration.Services.Replace(typeof (IHttpControllerSelector),
- new RouteVersionedControllerSelector(GlobalConfiguration.Configuration));
+ GlobalConfiguration.Configuration.Services.Replace(typeof (IHttpControllerSelector), new RouteVersionedControllerSelector(GlobalConfiguration.Configuration));
}
}
}
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Web.Http.Description;
+
+namespace VersioningTestApp.Models
+{
+ public class DocumentationModel
+ {
+ public DocumentationModel(IApiExplorer explorer)
+ {
+ if (explorer == null)
+ throw new ArgumentNullException("explorer");
+ this.Explorer = explorer;
+ }
+
+ public IApiExplorer Explorer { get; set; }
+ }
+}
@@ -0,0 +1,27 @@
+@model VersioningTestApp.Models.DocumentationModel
+
+<h1>Documentation</h1>
+<hr />
+<ul>
+@foreach (var version in Model.Explorer.ApiDescriptions.GroupBy(a => a.ActionDescriptor.ControllerDescriptor.ControllerType.Namespace))
+{
+ <li>
+ <h3>@version.Key.Split('.').Last()</h3>
+ <ul>
+ @foreach (var api in version)
+ {
+ <li>
+ (@api.HttpMethod) @api.RelativePath <br />
+ <ul>
+ <li><em>@api.Documentation</em></li>
+ @if(api.ActionDescriptor.ReturnType != null)
+ {
+ <li><em>returns</em> @api.ActionDescriptor.ReturnType.ToString()</li>
+ }
+ </ul>
+ </li>
+ }
+ </ul>
+ </li>
+}
+</ul>
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width" />
+ <title>Versioning Test App</title>
+</head>
+<body>
+ @RenderBody()
+ @RenderSection("scripts", required: false)
+</body>
+</html>
@@ -0,0 +1,3 @@
+@{
+ Layout = "~/Views/Shared/_Layout.cshtml";
+}
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+
+<configuration>
+ <configSections>
+ <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
+ <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
+ <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
+ </sectionGroup>
+ </configSections>
+
+ <system.web.webPages.razor>
+ <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
+ <pages pageBaseType="System.Web.Mvc.WebViewPage">
+ <namespaces>
+ <add namespace="System.Web.Mvc" />
+ <add namespace="System.Web.Mvc.Ajax" />
+ <add namespace="System.Web.Mvc.Html" />
+ <add namespace="System.Web.Routing" />
+ </namespaces>
+ </pages>
+ </system.web.webPages.razor>
+
+ <appSettings>
+ <add key="webpages:Enabled" value="false" />
+ </appSettings>
+
+ <system.web>
+ <httpHandlers>
+ <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
+ </httpHandlers>
+
+ <!--
+ Enabling request validation in view pages would cause validation to occur
+ after the input has already been processed by the controller. By default
+ MVC performs request validation before a controller processes the input.
+ To change this behavior apply the ValidateInputAttribute to a
+ controller or action.
+ -->
+ <pages
+ validateRequest="false"
+ pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
+ pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
+ userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
+ <controls>
+ <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
+ </controls>
+ </pages>
+ </system.web>
+
+ <system.webServer>
+ <validation validateIntegratedModeConfiguration="false" />
+
+ <handlers>
+ <remove name="BlockViewHandler"/>
+ <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
+ </handlers>
+ </system.webServer>
+</configuration>

0 comments on commit 79cac08

Please sign in to comment.