-
Notifications
You must be signed in to change notification settings - Fork 10.3k
JsonPatchDocument: Use application/json-patch+json content type in OpenAPI #62057
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
a913c6a
4c08402
4c44635
ef237ee
7548949
20c16b2
fca0801
c46b7c7
906d214
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,11 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http.Metadata; | ||
using Microsoft.AspNetCore.JsonPatch.SystemTextJson.Adapters; | ||
using Microsoft.AspNetCore.JsonPatch.SystemTextJson.Converters; | ||
using Microsoft.AspNetCore.JsonPatch.SystemTextJson.Exceptions; | ||
|
@@ -18,7 +21,7 @@ | |
// documents for cases where there's no class/DTO to work on. Typical use case: backend not built in | ||
// .NET or architecture doesn't contain a shared DTO layer. | ||
[JsonConverter(typeof(JsonPatchDocumentConverter))] | ||
public class JsonPatchDocument : IJsonPatchDocument | ||
public class JsonPatchDocument : IJsonPatchDocument, IEndpointParameterMetadataProvider | ||
{ | ||
public List<Operation> Operations { get; private set; } | ||
|
||
|
@@ -218,4 +221,17 @@ | |
|
||
return allOps; | ||
} | ||
|
||
/// <summary> | ||
/// Populates metadata for the related endpoint when this type is used as a parameter. | ||
/// </summary> | ||
/// <param name="parameter">The <see cref="ParameterInfo"/> for the endpoint parameter.</param> | ||
/// <param name="builder">The endpoint builder for the endpoint being constructed.</param> | ||
public static void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder) | ||
Check failure on line 230 in src/Features/JsonPatch.SystemTextJson/src/JsonPatchDocument.cs
|
||
{ | ||
ArgumentNullException.ThrowIfNull(parameter); | ||
ArgumentNullException.ThrowIfNull(builder); | ||
|
||
builder.Metadata.Add(new AcceptsMetadata(["application/json-patch+json"], parameter.ParameterType)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
using System.Reflection; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http.Metadata; | ||
using Microsoft.AspNetCore.JsonPatch.SystemTextJson.Adapters; | ||
using Microsoft.AspNetCore.JsonPatch.SystemTextJson.Converters; | ||
using Microsoft.AspNetCore.JsonPatch.SystemTextJson.Exceptions; | ||
|
@@ -23,7 +25,7 @@ | |
// including type data in the JsonPatchDocument serialized as JSON (to allow for correct deserialization) - that's | ||
// not according to RFC 6902, and would thus break cross-platform compatibility. | ||
[JsonConverter(typeof(JsonPatchDocumentConverterFactory))] | ||
public class JsonPatchDocument<TModel> : IJsonPatchDocument where TModel : class | ||
public class JsonPatchDocument<TModel> : IJsonPatchDocument, IEndpointParameterMetadataProvider where TModel : class | ||
{ | ||
public List<Operation<TModel>> Operations { get; private set; } | ||
|
||
|
@@ -657,6 +659,19 @@ | |
return allOps; | ||
} | ||
|
||
/// <summary> | ||
/// Populates metadata for the related endpoint when this type is used as a parameter. | ||
/// </summary> | ||
/// <param name="parameter">The <see cref="ParameterInfo"/> for the endpoint parameter.</param> | ||
/// <param name="builder">The endpoint builder for the endpoint being constructed.</param> | ||
public static void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder) | ||
Check failure on line 667 in src/Features/JsonPatch.SystemTextJson/src/JsonPatchDocumentOfT.cs
|
||
{ | ||
ArgumentNullException.ThrowIfNull(parameter); | ||
ArgumentNullException.ThrowIfNull(builder); | ||
|
||
builder.Metadata.Add(new AcceptsMetadata(["application/json-patch+json"], typeof(TModel))); | ||
} | ||
|
||
// Internal for testing | ||
internal string GetPath<TProp>(Expression<Func<TModel, TProp>> expr, string position) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
Microsoft.AspNetCore.JsonPatch.SystemTextJson.IJsonPatchDocument | ||
Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument | ||
Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.JsonPatchDocument() -> void | ||
Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.PopulateMetadata(System.Reflection.ParameterInfo parameter, Microsoft.AspNetCore.Builder.EndpointBuilder builder) -> void | ||
Check failure on line 9 in src/Features/JsonPatch.SystemTextJson/src/PublicAPI.Unshipped.txt
|
||
Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel>.JsonPatchDocument() -> void | ||
Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchError | ||
Microsoft.AspNetCore.JsonPatch.SystemTextJson.Operations.Operation | ||
|
@@ -52,6 +53,7 @@ | |
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.SerializerOptions.set -> void | ||
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument.Test(string path, object value) -> Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument | ||
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel> | ||
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel>.PopulateMetadata(System.Reflection.ParameterInfo parameter, Microsoft.AspNetCore.Builder.EndpointBuilder builder) -> void | ||
Check failure on line 56 in src/Features/JsonPatch.SystemTextJson/src/PublicAPI.Unshipped.txt
|
||
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel>.Add<TProp>(System.Linq.Expressions.Expression<System.Func<TModel, System.Collections.Generic.IList<TProp>>> path, TProp value) -> Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel> | ||
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel>.Add<TProp>(System.Linq.Expressions.Expression<System.Func<TModel, System.Collections.Generic.IList<TProp>>> path, TProp value, int position) -> Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel> | ||
~Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel>.Add<TProp>(System.Linq.Expressions.Expression<System.Func<TModel, TProp>> path, TProp value) -> Microsoft.AspNetCore.JsonPatch.SystemTextJson.JsonPatchDocument<TModel> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.JsonPatch.Adapters; | ||
using Microsoft.AspNetCore.JsonPatch.Converters; | ||
using Microsoft.AspNetCore.JsonPatch.Exceptions; | ||
|
@@ -12,13 +13,22 @@ | |
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
#if NET | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http.Metadata; | ||
#endif | ||
|
||
namespace Microsoft.AspNetCore.JsonPatch; | ||
|
||
// Implementation details: the purpose of this type of patch document is to allow creation of such | ||
// documents for cases where there's no class/DTO to work on. Typical use case: backend not built in | ||
// .NET or architecture doesn't contain a shared DTO layer. | ||
[JsonConverter(typeof(JsonPatchDocumentConverter))] | ||
#if NET | ||
public class JsonPatchDocument : IJsonPatchDocument, IEndpointParameterMetadataProvider | ||
#else | ||
public class JsonPatchDocument : IJsonPatchDocument | ||
#endif | ||
{ | ||
public List<Operation> Operations { get; private set; } | ||
|
||
|
@@ -218,4 +228,19 @@ | |
|
||
return allOps; | ||
} | ||
|
||
#if NET | ||
/// <summary> | ||
/// Populates metadata for the related endpoint when this type is used as a parameter. | ||
/// </summary> | ||
/// <param name="parameter">The <see cref="ParameterInfo"/> for the endpoint parameter.</param> | ||
/// <param name="builder">The endpoint builder for the endpoint being constructed.</param> | ||
public static void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder) | ||
Check failure on line 238 in src/Features/JsonPatch/src/JsonPatchDocument.cs
|
||
{ | ||
ArgumentNullException.ThrowIfNull(parameter); | ||
ArgumentNullException.ThrowIfNull(builder); | ||
|
||
builder.Metadata.Add(new AcceptsMetadata(["application/json-patch+json"], parameter.ParameterType)); | ||
} | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using System.Globalization; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.JsonPatch.Adapters; | ||
using Microsoft.AspNetCore.JsonPatch.Converters; | ||
using Microsoft.AspNetCore.JsonPatch.Exceptions; | ||
|
@@ -15,14 +16,23 @@ | |
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
#if NET | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http.Metadata; | ||
#endif | ||
|
||
namespace Microsoft.AspNetCore.JsonPatch; | ||
|
||
// Implementation details: the purpose of this type of patch document is to ensure we can do type-checking | ||
// when producing a JsonPatchDocument. However, we cannot send this "typed" over the wire, as that would require | ||
// including type data in the JsonPatchDocument serialized as JSON (to allow for correct deserialization) - that's | ||
// not according to RFC 6902, and would thus break cross-platform compatibility. | ||
[JsonConverter(typeof(TypedJsonPatchDocumentConverter))] | ||
#if NET | ||
public class JsonPatchDocument<TModel> : IJsonPatchDocument, IEndpointParameterMetadataProvider where TModel : class | ||
#else | ||
public class JsonPatchDocument<TModel> : IJsonPatchDocument where TModel : class | ||
#endif | ||
{ | ||
public List<Operation<TModel>> Operations { get; private set; } | ||
|
||
|
@@ -656,6 +666,21 @@ | |
return allOps; | ||
} | ||
|
||
#if NET | ||
/// <summary> | ||
/// Populates metadata for the related endpoint when this type is used as a parameter. | ||
/// </summary> | ||
/// <param name="parameter">The <see cref="ParameterInfo"/> for the endpoint parameter.</param> | ||
/// <param name="builder">The endpoint builder for the endpoint being constructed.</param> | ||
public static void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder) | ||
Check failure on line 675 in src/Features/JsonPatch/src/JsonPatchDocumentOfT.cs
|
||
{ | ||
ArgumentNullException.ThrowIfNull(parameter); | ||
ArgumentNullException.ThrowIfNull(builder); | ||
|
||
builder.Metadata.Add(new AcceptsMetadata(["application/json-patch+json"], typeof(TModel))); | ||
} | ||
#endif | ||
|
||
// Internal for testing | ||
internal string GetPath<TProp>(Expression<Func<TModel, TProp>> expr, string position) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
#nullable enable | ||
Microsoft.AspNetCore.JsonPatch.JsonPatchDocument.PopulateMetadata(System.Reflection.ParameterInfo parameter, Microsoft.AspNetCore.Builder.EndpointBuilder builder) -> void | ||
Check failure on line 2 in src/Features/JsonPatch/src/PublicAPI.Unshipped.txt
|
||
Microsoft.AspNetCore.JsonPatch.JsonPatchDocument<TModel>.PopulateMetadata(System.Reflection.ParameterInfo parameter, Microsoft.AspNetCore.Builder.EndpointBuilder builder) -> void | ||
Check failure on line 3 in src/Features/JsonPatch/src/PublicAPI.Unshipped.txt
|
Uh oh!
There was an error while loading. Please reload this page.