Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added two extra controllers to test with

  • Loading branch information...
commit e0333f78ced53eab5d69970fbfd70578686305bb 1 parent 06d26fe
Mike Trionfo authored
View
39 Swagger.Net.WebAPI/Controllers/BlogPostsController.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Web.Http;
+
+namespace Swagger.Net.WebApi.Controllers
+{
+ public class BlogPostsController : ApiController
+ {
+ // GET api/blogposts
+ public IEnumerable<string> Get()
+ {
+ return new string[] { "value1", "value2" };
+ }
+
+ // GET api/blogposts/5
+ public string Get(int id)
+ {
+ return "value";
+ }
+
+ // POST api/blogposts
+ public void Post([FromBody]string value)
+ {
+ }
+
+ // PUT api/blogposts/5
+ public void Put(int id, [FromBody]string value)
+ {
+ }
+
+ // DELETE api/blogposts/5
+ public void Delete(int id)
+ {
+ }
+ }
+}
View
56 Swagger.Net.WebAPI/Controllers/TagsController.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Web.Http;
+
+namespace Swagger.Net.WebApi.Controllers
+{
+ public class TagsController : ApiController
+ {
+ /// <summary>
+ /// Get all of the Tags
+ /// </summary>
+ /// <returns></returns>
+ public IEnumerable<string> Get()
+ {
+ return new string[] { "value1", "value2" };
+ }
+
+ /// <summary>
+ /// Get a single Tag by it's id
+ /// </summary>
+ /// <param name="id"></param>
+ /// <returns></returns>
+ public string Get(int id)
+ {
+ return "value";
+ }
+
+ /// <summary>
+ /// Create a new Tag
+ /// </summary>
+ /// <param name="value"></param>
+ public void Post([FromBody]string value)
+ {
+ }
+
+ /// <summary>
+ /// Update a Tag by it's id
+ /// </summary>
+ /// <param name="id"></param>
+ /// <param name="value"></param>
+ public void Put(int id, [FromBody]string value)
+ {
+ }
+
+ /// <summary>
+ /// Remove a Tag by it's id
+ /// </summary>
+ /// <param name="id"></param>
+ public void Delete(int id)
+ {
+ }
+ }
+}
View
2  Swagger.Net.WebAPI/Swagger.Net.WebApi.csproj
@@ -126,7 +126,9 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\SwaggerNet.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
+ <Compile Include="Controllers\BlogPostsController.cs" />
<Compile Include="Controllers\HomeController.cs" />
+ <Compile Include="Controllers\TagsController.cs" />
<Compile Include="Controllers\ValuesController.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
View
143 Swagger.Net/SwaggerActionFilter.cs
@@ -1,71 +1,72 @@
-using System;
-using System.Linq;
-using System.Net.Http;
-using System.Reflection;
-using System.Web.Http;
-using System.Web.Http.Controllers;
-using System.Web.Http.Filters;
-
-namespace Swagger.Net
-{
- /// <summary>
- /// Determines if any request hit the Swagger route. Moves on if not, otherwise responds with JSON Swagger spec doc
- /// </summary>
- public class SwaggerActionFilter : ActionFilterAttribute
- {
- /// <summary>
- /// Executes each request to give either a JSON Swagger spec doc or passes through the request
- /// </summary>
- /// <param name="actionContext">Context of the action</param>
- public override void OnActionExecuting(HttpActionContext actionContext)
- {
- var docRequest = actionContext.ControllerContext.RouteData.Values.ContainsKey(SwaggerGen.SWAGGER);
-
- if (!docRequest)
- {
- base.OnActionExecuting(actionContext);
- return;
- }
-
- HttpResponseMessage response = new HttpResponseMessage();
-
- response.Content = new ObjectContent<ResourceListing>(
- getDocs(actionContext),
- actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
-
- actionContext.Response = response;
- }
-
- private ResourceListing getDocs(HttpActionContext actionContext)
- {
- var docProvider = (XmlCommentDocumentationProvider)GlobalConfiguration.Configuration.Services.GetDocumentationProvider();
-
- ResourceListing r = SwaggerGen.CreateResourceListing(actionContext);
-
- foreach (var api in GlobalConfiguration.Configuration.Services.GetApiExplorer().ApiDescriptions)
- {
- string apiControllerName = api.ActionDescriptor.ControllerDescriptor.ControllerName;
- if (api.Route.Defaults.ContainsKey(SwaggerGen.SWAGGER) ||
- apiControllerName.ToUpper().Equals(SwaggerGen.SWAGGER.ToUpper())) continue;
-
- // Make sure we only report the current controller docs
- if (apiControllerName != actionContext.ControllerContext.ControllerDescriptor.ControllerName)
- continue;
-
- ResourceApi rApi = SwaggerGen.CreateResourceApi(api);
- r.apis.Add(rApi);
-
- ResourceApiOperation rApiOperation = SwaggerGen.CreateResourceApiOperation(api, docProvider);
- rApi.operations.Add(rApiOperation);
-
- foreach (var param in api.ParameterDescriptions)
- {
- ResourceApiOperationParameter parameter = SwaggerGen.CreateResourceApiOperationParameter(api, param, docProvider);
- rApiOperation.parameters.Add(parameter);
- }
- }
-
- return r;
- }
- }
-}
+using System;
+using System.Linq;
+using System.Net.Http;
+using System.Reflection;
+using System.Web.Http;
+using System.Web.Http.Controllers;
+using System.Web.Http.Filters;
+
+namespace Swagger.Net
+{
+ /// <summary>
+ /// Determines if any request hit the Swagger route. Moves on if not, otherwise responds with JSON Swagger spec doc
+ /// </summary>
+ public class SwaggerActionFilter : ActionFilterAttribute
+ {
+ /// <summary>
+ /// Executes each request to give either a JSON Swagger spec doc or passes through the request
+ /// </summary>
+ /// <param name="actionContext">Context of the action</param>
+ public override void OnActionExecuting(HttpActionContext actionContext)
+ {
+ var docRequest = actionContext.ControllerContext.RouteData.Values.ContainsKey(SwaggerGen.SWAGGER);
+
+ if (!docRequest)
+ {
+ base.OnActionExecuting(actionContext);
+ return;
+ }
+
+ HttpResponseMessage response = new HttpResponseMessage();
+
+ response.Content = new ObjectContent<ResourceListing>(
+ getDocs(actionContext),
+ actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
+
+ actionContext.Response = response;
+ }
+
+ private ResourceListing getDocs(HttpActionContext actionContext)
+ {
+ var docProvider = (XmlCommentDocumentationProvider)GlobalConfiguration.Configuration.Services.GetDocumentationProvider();
+
+ ResourceListing r = SwaggerGen.CreateResourceListing(actionContext);
+
+ foreach (var api in GlobalConfiguration.Configuration.Services.GetApiExplorer().ApiDescriptions)
+ {
+ string apiControllerName = api.ActionDescriptor.ControllerDescriptor.ControllerName;
+ if (api.Route.Defaults.ContainsKey(SwaggerGen.SWAGGER) ||
+ apiControllerName.ToUpper().Equals(SwaggerGen.SWAGGER.ToUpper()))
+ continue;
+
+ // Make sure we only report the current controller docs
+ if (apiControllerName.Equals(actionContext.ControllerContext.ControllerDescriptor.ControllerName))
+ continue;
+
+ ResourceApi rApi = SwaggerGen.CreateResourceApi(api);
+ r.apis.Add(rApi);
+
+ ResourceApiOperation rApiOperation = SwaggerGen.CreateResourceApiOperation(api, docProvider);
+ rApi.operations.Add(rApiOperation);
+
+ foreach (var param in api.ParameterDescriptions)
+ {
+ ResourceApiOperationParameter parameter = SwaggerGen.CreateResourceApiOperationParameter(api, param, docProvider);
+ rApiOperation.parameters.Add(parameter);
+ }
+ }
+
+ return r;
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.