Fix bugs in the routing in sample APIs to allow the endpoitns to be hit.

1) Modify web.config to allow PUT and DELETE to be hit. MVC by default only allows GET and POST.

2) Remove the front slash '/' and the query param from the attribute-based routing since they are prohibited.

3) Register the MVC attribute-based routing in RouteConfig.cs

4) Rename the controllers. MVC requires the controllers to end with suffix `Controller`. If we don't do this, we cannot hit the endpoints :(

5) Fix wrong parameters in SampleV4Controller.
This commit is contained in:
Perth Charernwattanagul 2018-08-27 16:08:11 -07:00
Родитель aa458b89e4
Коммит fd96a1e679
7 изменённых файлов: 36 добавлений и 25 удалений

Просмотреть файл

@ -24,6 +24,8 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
}
}
}

Просмотреть файл

@ -13,7 +13,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <summary>
/// Define V1 operations.
/// </summary>
public class SampleControllerV1 : ApiController
public class SampleV1Controller : ApiController
{
/// <summary>
/// Sample Get 1
@ -32,7 +32,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <swagger>Group2</swagger>
/// <returns>The sample object 1</returns>
[HttpGet]
[Route("/V1/samples/{id}?queryBool={queryBool}")]
[Route("V1/samples/{id}")]
public Task<SampleObject1> SampleGet1(string id, bool queryBool)
{
throw new NotSupportedException();
@ -51,8 +51,8 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <response code="400"><see cref="string"/>Bad request</response>
/// <returns>The sample object 3</returns>
[HttpGet]
[Route("/V1/samples")]
public Task<SampleObject3> SampleGet2()
[Route("V1/samples")]
public async Task<SampleObject3> SampleGet2()
{
throw new NotSupportedException();
}
@ -70,7 +70,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <response code="200"><see cref="SampleObject1"/>Sample object posted</response>
/// <response code="400"><see cref="string"/>Bad request</response>
[HttpPost]
[Route("/V1/samples")]
[Route("V1/samples")]
public Task<SampleObject1> SamplePost([FromBody] SampleObject3 sampleObject)
{
throw new NotSupportedException();
@ -91,7 +91,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <response code="400"><see cref="string"/>Bad request</response>
/// <returns>The sample object 1</returns>
[HttpPut]
[Route("/V1/samples/{id}")]
[Route("V1/samples/{id}")]
public Task<SampleObject1> SamplePut(string id, [FromBody] SampleObject1 sampleObject)
{
throw new NotSupportedException();

Просмотреть файл

@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <summary>
/// Defines V2 operations.
/// </summary>
public class SampleControllerV2 : ApiController
public class SampleV2Controller : ApiController
{
/// <summary>
/// Sample delete
@ -29,7 +29,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <response code="200"><see cref="SampleObject1"/>Sample object deleted</response>
/// <response code="400"><see cref="string"/>Bad request</response>
[HttpDelete]
[Route("/V2/samples/{id}")]
[Route("V2/samples/{id}")]
public Task<SampleObject1> DeleteEntity(string id)
{
throw new NotSupportedException();
@ -47,7 +47,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <response code="200"><see cref="List{T}"/>where T is <see cref="SampleObject2"/>List of sample objects</response>
/// <response code="400"><see cref="string"/>Bad request</response>
[HttpGet]
[Route("/V2/samples")]
[Route("V2/samples")]
public Task<List<SampleObject2>> SampleGet1()
{
throw new NotSupportedException();
@ -67,7 +67,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <response code="200"><see cref="SampleObject2"/>Sample object retrieved</response>
/// <response code="400"><see cref="string"/>Bad request</response>
[HttpGet]
[Route("/V2/samples/{id}?queryString={queryString}")]
[Route("V2/samples/{id}")]
public Task<SampleObject2> SampleGet2(string id, string queryString)
{
throw new NotSupportedException();

Просмотреть файл

@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <summary>
/// Defines V3 operations.
/// </summary>
public class SampleControllerV3 : ApiController
public class SampleV3Controller : ApiController
{
/// <summary>
/// Sample get 1
@ -34,7 +34,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// </response>
/// <response code="400"><see cref="string"/>Bad request</response>
[HttpGet]
[Route("/V3/samples")]
[Route("V3/samples")]
public Task<List<ISampleObject4<SampleObject1, SampleObject2>>> SampleGet1()
{
throw new NotSupportedException();
@ -59,7 +59,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// </response>
/// <response code="400"><see cref="string"/>Bad request</response>
[HttpGet]
[Route("/V3/samples/{id}?queryString={queryString}")]
[Route("V3/samples/{id}")]
public Task<ISampleObject4<SampleObject1, SampleObject2>> SampleGet2(string id, string queryString)
{
throw new NotSupportedException();

Просмотреть файл

@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// <summary>
/// Defines V4 operations.
/// </summary>
public class SampleControllerV4 : ApiController
public class SampleV4Controller : ApiController
{
/// <summary>
/// Sample get 1
@ -34,7 +34,7 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// </response>
/// <response code="400"><see cref="string"/>Bad request</response>
[HttpGet]
[Route("/V4/samples")]
[Route("V4/samples")]
public Task<List<ISampleObject4<SampleObject1, SampleObject4>>> SampleGet1()
{
throw new NotSupportedException();
@ -70,8 +70,8 @@ namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApi
/// </response>
/// <response code="400"><see cref="string"/>Bad request</response>
[HttpPost]
[Route("/V4/samples")]
public Task<SampleObject4> SamplePost1(SampleObject1 sampleObject1, string id)
[Route("V4/samples/{id}")]
public Task<SampleObject4> SamplePost1([FromBody] SampleObject1 sampleObject1, string id, bool queryBool)
{
throw new NotSupportedException();
}

Просмотреть файл

@ -112,10 +112,10 @@
<ItemGroup>
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\SampleControllerV1.cs" />
<Compile Include="Controllers\SampleControllerV3.cs" />
<Compile Include="Controllers\SampleControllerV2.cs" />
<Compile Include="Controllers\SampleControllerV4.cs" />
<Compile Include="Controllers\SampleV1Controller.cs" />
<Compile Include="Controllers\SampleV3Controller.cs" />
<Compile Include="Controllers\SampleV2Controller.cs" />
<Compile Include="Controllers\SampleV4Controller.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>

Просмотреть файл

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
@ -17,6 +17,15 @@
</system.Web>
-->
<system.web>
<compilation targetFramework="4.6.2" />
<compilation targetFramework="4.6.2" debug="true"/>
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*."
verb="GET,HEAD,POST,DEBUG,PUT,DELETE,OPTIONS"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</configuration>