diff --git a/eng/Versions.props b/eng/Versions.props
index 7fa6c5c6c32b..717c92dbbebe 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -335,8 +335,8 @@
$(XunitVersion)
2.8.2
5.2.2
- 1.6.17
- 1.6.17
+ 2.0.0-preview2
+ 2.0.0-preview2
6.0.322601
1.10.93
diff --git a/eng/testing/linker/project.csproj.template b/eng/testing/linker/project.csproj.template
index ea368a6caa54..d78b5bfc991e 100644
--- a/eng/testing/linker/project.csproj.template
+++ b/eng/testing/linker/project.csproj.template
@@ -16,6 +16,8 @@
$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated
false
+
+ $(NoWarn);IL2104;IL3053
{AdditionalProperties}
@@ -27,4 +29,19 @@
{AdditionalProjectReferences}
+
+
+
+
+
+
+
+ true
+ true
+
+
+
+
diff --git a/src/OpenApi/perf/Microbenchmarks/OpenApiSchemaComparerBenchmark.cs b/src/OpenApi/perf/Microbenchmarks/OpenApiSchemaComparerBenchmark.cs
deleted file mode 100644
index 64bf0ce2736a..000000000000
--- a/src/OpenApi/perf/Microbenchmarks/OpenApiSchemaComparerBenchmark.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Globalization;
-using BenchmarkDotNet.Attributes;
-using Microsoft.OpenApi.Any;
-using Microsoft.OpenApi.Interfaces;
-using Microsoft.OpenApi.Models;
-
-namespace Microsoft.AspNetCore.OpenApi.Microbenchmarks;
-
-public class OpenApiSchemaComparerBenchmark
-{
- [Params(1, 10, 100)]
- public int ElementCount { get; set; }
-
- private OpenApiSchema _schema;
-
- [GlobalSetup]
- public void OpenApiSchema_Setup()
- {
- _schema = new OpenApiSchema
- {
- AdditionalProperties = GenerateInnerSchema(),
- AdditionalPropertiesAllowed = true,
- AllOf = Enumerable.Range(0, ElementCount).Select(_ => GenerateInnerSchema()).ToList(),
- AnyOf = Enumerable.Range(0, ElementCount).Select(_ => GenerateInnerSchema()).ToList(),
- Deprecated = true,
- Default = new OpenApiString("default"),
- Description = "description",
- Discriminator = new OpenApiDiscriminator(),
- Example = new OpenApiString("example"),
- ExclusiveMaximum = true,
- ExclusiveMinimum = true,
- Extensions = new Dictionary
- {
- ["key"] = new OpenApiString("value")
- },
- ExternalDocs = new OpenApiExternalDocs(),
- Enum = Enumerable.Range(0, ElementCount).Select(_ => (IOpenApiAny)new OpenApiString("enum")).ToList(),
- OneOf = Enumerable.Range(0, ElementCount).Select(_ => GenerateInnerSchema()).ToList(),
- };
-
- static OpenApiSchema GenerateInnerSchema() => new OpenApiSchema
- {
- Properties = Enumerable.Range(0, 10).ToDictionary(i => i.ToString(CultureInfo.InvariantCulture), _ => new OpenApiSchema()),
- Deprecated = true,
- Default = new OpenApiString("default"),
- Description = "description",
- Example = new OpenApiString("example"),
- Extensions = new Dictionary
- {
- ["key"] = new OpenApiString("value")
- },
- };
- }
-
- [Benchmark]
- public int OpenApiSchema_GetHashCode() => OpenApiSchemaComparer.Instance.GetHashCode(_schema);
-
- [Benchmark]
- public OpenApiSchema OpenApiSchema_Clone() => OpenApiSchemaExtensions.Clone(_schema);
-}
diff --git a/src/OpenApi/perf/Microbenchmarks/TransformersBenchmark.cs b/src/OpenApi/perf/Microbenchmarks/TransformersBenchmark.cs
index a5a117b54bd9..d7fca2c1bcf5 100644
--- a/src/OpenApi/perf/Microbenchmarks/TransformersBenchmark.cs
+++ b/src/OpenApi/perf/Microbenchmarks/TransformersBenchmark.cs
@@ -104,11 +104,11 @@ public void SchemaTransformer_Setup()
{
if (context.JsonTypeInfo.Type == typeof(Todo) && context.ParameterDescription != null)
{
- schema.Extensions["x-my-extension"] = new OpenApiString(context.ParameterDescription.Name);
+ schema.Extensions["x-my-extension"] = new OpenApiAny(context.ParameterDescription.Name);
}
else
{
- schema.Extensions["x-my-extension"] = new OpenApiString("response");
+ schema.Extensions["x-my-extension"] = new OpenApiAny("response");
}
return Task.CompletedTask;
});
@@ -177,11 +177,11 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
{
if (context.JsonTypeInfo.Type == typeof(Todo) && context.ParameterDescription != null)
{
- schema.Extensions["x-my-extension"] = new OpenApiString(context.ParameterDescription.Name);
+ schema.Extensions["x-my-extension"] = new OpenApiAny(context.ParameterDescription.Name);
}
else
{
- schema.Extensions["x-my-extension"] = new OpenApiString("response");
+ schema.Extensions["x-my-extension"] = new OpenApiAny("response");
}
return Task.CompletedTask;
}
diff --git a/src/OpenApi/sample/Transformers/AddExternalDocsTransformer.cs b/src/OpenApi/sample/Transformers/AddExternalDocsTransformer.cs
index 6af558870e0d..acc4402c32f6 100644
--- a/src/OpenApi/sample/Transformers/AddExternalDocsTransformer.cs
+++ b/src/OpenApi/sample/Transformers/AddExternalDocsTransformer.cs
@@ -29,7 +29,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
{
if (Uri.TryCreate(configuration["DocumentationBaseUrl"], UriKind.Absolute, out var baseUri))
{
- var url = new Uri(baseUri, $"/api/docs/schemas/{Uri.EscapeDataString(schema.Type)}");
+ var url = new Uri(baseUri, $"/api/docs/schemas/{Uri.EscapeDataString(schema.Type.ToString()!)}");
schema.ExternalDocs = new OpenApiExternalDocs
{
diff --git a/src/OpenApi/sample/Transformers/OperationTransformers.cs b/src/OpenApi/sample/Transformers/OperationTransformers.cs
index b1427762e09b..0c90f63d8e1a 100644
--- a/src/OpenApi/sample/Transformers/OperationTransformers.cs
+++ b/src/OpenApi/sample/Transformers/OperationTransformers.cs
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.AspNetCore.OpenApi;
-using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
@@ -15,7 +14,7 @@ public static OpenApiOptions AddHeader(this OpenApiOptions options, string heade
return options.AddOperationTransformer((operation, context, cancellationToken) =>
{
var schema = OpenApiTypeMapper.MapTypeToOpenApiPrimitiveType(typeof(string));
- schema.Default = new OpenApiString(defaultValue);
+ schema.Default = defaultValue;
operation.Parameters ??= [];
operation.Parameters.Add(new OpenApiParameter
{
diff --git a/src/OpenApi/src/Comparers/ComparerHelpers.cs b/src/OpenApi/src/Comparers/ComparerHelpers.cs
deleted file mode 100644
index 3baa530db866..000000000000
--- a/src/OpenApi/src/Comparers/ComparerHelpers.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace Microsoft.AspNetCore.OpenApi;
-
-internal static class ComparerHelpers
-{
- internal static bool DictionaryEquals(IDictionary x, IDictionary y, IEqualityComparer comparer)
- where TKey : notnull
- where TValue : notnull
- {
- if (x is Dictionary xDictionary && y is Dictionary yDictionary)
- {
- return DictionaryEquals(xDictionary, yDictionary, comparer);
- }
-
- if (x.Keys.Count != y.Keys.Count)
- {
- return false;
- }
-
- foreach (var key in x.Keys)
- {
- if (!y.TryGetValue(key, out var value) || !comparer.Equals(x[key], value))
- {
- return false;
- }
- }
-
- return true;
- }
-
- // Private method to avoid interface dispatch.
- private static bool DictionaryEquals(Dictionary x, Dictionary y, IEqualityComparer comparer)
- where TKey : notnull
- where TValue : notnull
- {
- if (x.Keys.Count != y.Keys.Count)
- {
- return false;
- }
-
- foreach (var key in x.Keys)
- {
- if (!y.TryGetValue(key, out var value) || !comparer.Equals(x[key], value))
- {
- return false;
- }
- }
-
- return true;
- }
-
- internal static bool ListEquals(IList x, IList y, IEqualityComparer comparer)
- {
- if (x is List xList && y is List yList)
- {
- return ListEquals(xList, yList, comparer);
- }
-
- if (x.Count != y.Count)
- {
- return false;
- }
-
- for (var i = 0; i < x.Count; i++)
- {
- if (!comparer.Equals(x[i], y[i]))
- {
- return false;
- }
- }
-
- return true;
- }
-
- // Private method to avoid interface dispatch.
- private static bool ListEquals(List x, List y, IEqualityComparer comparer)
- {
- if (x.Count != y.Count)
- {
- return false;
- }
-
- for (var i = 0; i < x.Count; i++)
- {
- if (!comparer.Equals(x[i], y[i]))
- {
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/src/OpenApi/src/Comparers/OpenApiAnyComparer.cs b/src/OpenApi/src/Comparers/OpenApiAnyComparer.cs
deleted file mode 100644
index 5ba27568899d..000000000000
--- a/src/OpenApi/src/Comparers/OpenApiAnyComparer.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System.Linq;
-using Microsoft.OpenApi.Any;
-using Microsoft.OpenApi.Interfaces;
-
-namespace Microsoft.AspNetCore.OpenApi;
-
-internal sealed class OpenApiAnyComparer : IEqualityComparer, IEqualityComparer
-{
- public static OpenApiAnyComparer Instance { get; } = new OpenApiAnyComparer();
-
- public bool Equals(IOpenApiAny? x, IOpenApiAny? y)
- {
- if (x is null && y is null)
- {
- return true;
- }
- if (x is null || y is null)
- {
- return false;
- }
- if (object.ReferenceEquals(x, y))
- {
- return true;
- }
-
- return x.AnyType == y.AnyType &&
- (x switch
- {
- OpenApiNull _ => y is OpenApiNull,
- OpenApiArray arrayX => y is OpenApiArray arrayY && ComparerHelpers.ListEquals(arrayX, arrayY, Instance),
- OpenApiObject objectX => y is OpenApiObject objectY && ComparerHelpers.DictionaryEquals(objectX, objectY, Instance),
- OpenApiBinary binaryX => y is OpenApiBinary binaryY && binaryX.Value.SequenceEqual(binaryY.Value),
- OpenApiInteger integerX => y is OpenApiInteger integerY && integerX.Value == integerY.Value,
- OpenApiLong longX => y is OpenApiLong longY && longX.Value == longY.Value,
- OpenApiDouble doubleX => y is OpenApiDouble doubleY && doubleX.Value == doubleY.Value,
- OpenApiFloat floatX => y is OpenApiFloat floatY && floatX.Value == floatY.Value,
- OpenApiBoolean booleanX => y is OpenApiBoolean booleanY && booleanX.Value == booleanY.Value,
- OpenApiString stringX => y is OpenApiString stringY && stringX.Value == stringY.Value,
- OpenApiPassword passwordX => y is OpenApiPassword passwordY && passwordX.Value == passwordY.Value,
- OpenApiByte byteX => y is OpenApiByte byteY && byteX.Value.SequenceEqual(byteY.Value),
- OpenApiDate dateX => y is OpenApiDate dateY && dateX.Value == dateY.Value,
- OpenApiDateTime dateTimeX => y is OpenApiDateTime dateTimeY && dateTimeX.Value == dateTimeY.Value,
- _ => x.Equals(y)
- });
- }
-
- public int GetHashCode(IOpenApiAny obj)
- {
- var hashCode = new HashCode();
- hashCode.Add(obj.AnyType);
- if (obj is IOpenApiPrimitive primitive)
- {
- hashCode.Add(primitive.PrimitiveType);
- }
- if (obj is OpenApiBinary binary)
- {
- hashCode.AddBytes(binary.Value);
- }
- if (obj is OpenApiByte bytes)
- {
- hashCode.AddBytes(bytes.Value);
- }
- hashCode.Add