From 3f54492930bf4ac2f2741de0f6bb7a060c3af9d4 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Tue, 7 Oct 2014 15:17:11 -0700 Subject: [PATCH] [Fixes #885] API Explorer: Link Generation 1) Expose the simplified relative path template by cleaning up constraints, optional and catch all tokens from the template. 2) Expose the parameters on the route template as API parameters. 3) Combine parameters from the route and the action descriptor when the parameter doesn't come from the body. #886 will refine this. 4) Expose optionality and constraints for path parameters. Open question: Should we explicitly expose IsCatchAll? --- .../ApiExplorerSamples/ProductsController.cs | 4 +- .../Views/ApiExplorer/_ApiDescription.cshtml | 8 +- .../Description/ApiParameterDescription.cs | 5 + .../Description/ApiParameterSource.cs | 1 + .../DefaultApiDescriptionProvider.cs | 197 ++++++++++-- .../DefaultApiDescriptionProviderTest.cs | 285 +++++++++++++++++- .../ApiExplorerTest.cs | 252 +++++++++++++++- .../ApiExplorerDataFilter.cs | 5 +- ...eAndPathParametersInformationController.cs | 38 +++ 9 files changed, 748 insertions(+), 47 deletions(-) create mode 100644 test/WebSites/ApiExplorerWebSite/Controllers/ApiExplorerRouteAndPathParametersInformationController.cs diff --git a/samples/MvcSample.Web/Controllers/ApiExplorerSamples/ProductsController.cs b/samples/MvcSample.Web/Controllers/ApiExplorerSamples/ProductsController.cs index fd64e2b472..538791b98d 100644 --- a/samples/MvcSample.Web/Controllers/ApiExplorerSamples/ProductsController.cs +++ b/samples/MvcSample.Web/Controllers/ApiExplorerSamples/ProductsController.cs @@ -9,7 +9,7 @@ namespace MvcSample.Web.ApiExplorerSamples [Route("api/Products")] public class ProductsController : Controller { - [HttpGet("{id}")] + [HttpGet("{id:int}")] public Product GetById(int id) { return null; @@ -22,7 +22,7 @@ namespace MvcSample.Web.ApiExplorerSamples } [Produces("application/json", Type = typeof(ProductOrderConfirmation))] - [HttpPut("{id}/Buy")] + [HttpPut("{id:int}/Buy")] public IActionResult Buy(int projectId, int quantity = 1) { return null; diff --git a/samples/MvcSample.Web/Views/ApiExplorer/_ApiDescription.cshtml b/samples/MvcSample.Web/Views/ApiExplorer/_ApiDescription.cshtml index b0e24064b4..f3e73a79b2 100644 --- a/samples/MvcSample.Web/Views/ApiExplorer/_ApiDescription.cshtml +++ b/samples/MvcSample.Web/Views/ApiExplorer/_ApiDescription.cshtml @@ -13,7 +13,11 @@ } @@ -22,7 +26,7 @@ {

Response Formats: