Skip to content

Commit bf9b7dd

Browse files
[OpenApi] Remove JsonPatch.SystemTextJson dep
Remove the dependency on `Microsoft.AspNetCore.JsonPatch.SystemTextJson` as it creates type warnings, and instead check the types by name.
1 parent fe2dba7 commit bf9b7dd

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/OpenApi/src/Extensions/TypeExtensions.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using Microsoft.AspNetCore.JsonPatch.SystemTextJson;
5-
64
namespace Microsoft.AspNetCore.OpenApi;
75

86
internal static class TypeExtensions
97
{
8+
private const string JsonPatchDocumentNamespace = "Microsoft.AspNetCore.JsonPatch.SystemTextJson";
9+
private const string JsonPatchDocumentName = "JsonPatchDocument";
10+
private const string JsonPatchDocumentNameOfT = "JsonPatchDocument`1";
11+
1012
public static bool IsJsonPatchDocument(this Type type)
1113
{
12-
if (type.IsAssignableTo(typeof(JsonPatchDocument)))
13-
{
14-
return true;
15-
}
16-
14+
// We cannot depend on the actual runtime type as
15+
// Microsoft.AspNetCore.JsonPatch.SystemTextJson is not
16+
// AoT compatible so cannot be referenced by Microsoft.AspNetCore.OpenApi.
1717
var modelType = type;
1818

1919
while (modelType != null && modelType != typeof(object))
2020
{
21-
if (modelType.IsGenericType && modelType.GetGenericTypeDefinition() == typeof(JsonPatchDocument<>))
21+
if (modelType.Namespace == JsonPatchDocumentNamespace &&
22+
(modelType.Name == JsonPatchDocumentName || modelType.Name.StartsWith(JsonPatchDocumentNameOfT, StringComparison.Ordinal)))
2223
{
2324
return true;
2425
}

src/OpenApi/src/Microsoft.AspNetCore.OpenApi.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<Reference Include="Microsoft.AspNetCore" />
1818
<Reference Include="Microsoft.AspNetCore.Http.Abstractions" />
1919
<Reference Include="Microsoft.AspNetCore.Http.Results" />
20-
<Reference Include="Microsoft.AspNetCore.JsonPatch.SystemTextJson" />
2120
<Reference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" />
2221
<Reference Include="Microsoft.AspNetCore.Mvc.Core" />
2322
<Reference Include="Microsoft.AspNetCore.Routing" />

0 commit comments

Comments
 (0)