Skip to content

Update media type for JSON Patch #62988

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

Merged
merged 1 commit into from
Aug 1, 2025
Merged

Conversation

martincostello
Copy link
Member

Update media type for JSON Patch

Use Content-Type: application/json-patch+json for JSON patch.

Description

  • Use Content-Type: application/json-patch+json for JSON patch.
  • Fix some code analyzer suggestions.
  • Fix broken build.cmd for JsonPatch.

Adapted from #62057.

Fixes #61956.

- Use `Content-Type: application/json-patch+json` for JSON patch.
- Fix some code analyzer suggestions.
- Fix broken `build.cmd` for JsonPatch.

Adapted from dotnet#62057.

Resolves dotnet#61956.
@Copilot Copilot AI review requested due to automatic review settings July 29, 2025 13:34
@martincostello martincostello requested review from captainsafia and a team as code owners July 29, 2025 13:34
@github-actions github-actions bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 29, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the media type for JSON Patch requests from the default application/json to the RFC 6902 compliant application/json-patch+json. The implementation adds IEndpointParameterMetadataProvider to the JsonPatchDocument classes to automatically configure the correct content type in OpenAPI documentation and ASP.NET Core endpoints.

Key changes:

  • Implements IEndpointParameterMetadataProvider in JsonPatchDocument classes to set proper content type metadata
  • Updates code to use modern C# patterns (collection expressions, object initializers)
  • Fixes the build script path for the JsonPatch project

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
JsonPatchDocumentOfT.cs (both versions) Implements metadata provider interface and modernizes code syntax
JsonPatchDocument.cs (both versions) Implements metadata provider interface and modernizes code syntax
Sample project files Adds JsonPatch dependency and test endpoint for demonstration
OpenAPI test snapshots Shows updated content type in generated documentation
Project files Adds required HTTP abstractions dependency
build.cmd Fixes incorrect repository root path

"content": {
"application/json-patch+json": {
"schema": {
"$ref": "#/components/schemas/JsonPatchDocumentOfParentObject"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we need a custom JSON convert to model the schema for JSON path document. I assume the schema looks something like:

{
  type: "object",
  properties: {
     "op": "string",
      "path": "string",
      "value": "string"
  }
}

@mikekistler Sanity checking this by you. Does it seem sufficient to use the same schema for all JsonPatchDocument types or should we figure out some way to capture the properties of the model that you're patchinmg in the schema?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If needed I could look into doing that in a follow-up, as that's existing behaviour anyway without the media type change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the JsonPatchDocumentOfParentObject is just this (line 624):

 "JsonPatchDocumentOfParentObject": { },

I think we can tackle the issue of the patch body schema in a separate PR. We should probably open an issue for this. I don't have an issue with using the same schema for all patch operations, but it should be more like the schema you show above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sounds good. We can probably add special handling for the JsonPatchDocument type the same way we do for IFormFile and PipeReader. Hopefully, there's no referemce issues adding a reference to the patching library in the OpenAPI lib.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM sans schema follow-up!

@captainsafia captainsafia merged commit 9720579 into dotnet:main Aug 1, 2025
31 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-rc1 milestone Aug 1, 2025
@martincostello martincostello deleted the gh-62057 branch August 1, 2025 18:20
martincostello added a commit to martincostello/aspnetcore that referenced this pull request Aug 3, 2025
Pick up changes from dotnet#62988.

Resolves dotnet#63073.
martincostello added a commit to martincostello/aspnetcore that referenced this pull request Aug 3, 2025
Pick up changes from dotnet#62988.

Resolves dotnet#63073.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates community-contribution Indicates that the PR has been added by a community member feature-json-patch feature-openapi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON Patch request body should use content-type application/json-patch+json
3 participants