Skip to content

[WORKING] Method: PATCH, Both v1 and v2 Controller has consumes=application/merge-patch+json #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/aspnetcore/BasicSample/BasicSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Microsoft.Examples</RootNamespace>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Microsoft.Examples</RootNamespace>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Microsoft.Examples</RootNamespace>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion samples/aspnetcore/SwaggerSample/SwaggerSample.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Microsoft.Examples</RootNamespace>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml</DocumentationFile>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,26 @@ public IActionResult Post( [FromBody] Order order )
order.Id = 42;
return CreatedAtAction( nameof( Get ), new { id = order.Id }, order );
}

/// <summary>
/// Updates an existing order.
/// </summary>
/// <param name="order">The order to update.</param>
/// <returns>The created order.</returns>
/// <response code="204">The order was successfully updated.</response>
/// <response code="400">The order is invalid.</response>
/// <response code="404">The order does not exist.</response>
[MapToApiVersion( "1.0" )]
[HttpPatch("{id:int}")]
[Produces("application/json")]
[Consumes("application/merge-patch+json")]
[ProducesResponseType(204)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public IActionResult Patch(int id, [FromBody] Order order)
{
order.Id = 1; // if id=1 then it is returned from V1 OrdersController.cs
return CreatedAtAction(nameof(Get), new { id = order.Id }, order);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,25 @@ public IActionResult Post( [FromBody] Order order )
order.Id = 42;
return CreatedAtAction( nameof( Get ), new { id = order.Id }, order );
}

/// <summary>
/// Updates an existing order.
/// </summary>
/// <param name="order">The order to update.</param>
/// <returns>The created order.</returns>
/// <response code="204">The order was successfully updated.</response>
/// <response code="400">The order is invalid.</response>
/// <response code="404">The order does not exist.</response>
[HttpPatch( "{id:int}" )]
[Produces( "application/json" )]
[Consumes( "application/merge-patch+json" )]
[ProducesResponseType( 204 )]
[ProducesResponseType( 400 )]
[ProducesResponseType( 404 )]
public IActionResult Patch( int id, [FromBody] Order order )
{
order.Id = 2; // if id=2 then it is returned from V2 OrdersController.cs
return CreatedAtAction( nameof( Get ), new { id = order.Id }, order );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Description>ASP.NET Core MVC API explorer functionality for discovering metadata such as the list of API-versioned controllers and actions, and their URLs and allowed HTTP methods.</Description>
<RootNamespace>Microsoft.AspNetCore.Mvc.ApiExplorer</RootNamespace>
<PackageTags>Microsoft;AspNet;AspNetCore;Versioning;ApiExplorer</PackageTags>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Description>A service API versioning library for Microsoft ASP.NET Core.</Description>
<RootNamespace>Microsoft.AspNetCore.Mvc</RootNamespace>
<PackageTags>Microsoft;AspNet;AspNetCore;Versioning</PackageTags>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<RootNamespace>Microsoft.AspNetCore.Mvc.ApiExplorer</RootNamespace>
<PreserveCompilationContext>true</PreserveCompilationContext>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<RootNamespace>Microsoft.AspNetCore.Mvc</RootNamespace>
<PreserveCompilationContext>true</PreserveCompilationContext>
<LangVersion>default</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down