Skip to content

Commit c430536

Browse files
authored
Update to Microsoft.OpenApi 1.6.17 (#57201)
1 parent 2a67ffb commit c430536

File tree

14 files changed

+51
-98
lines changed

14 files changed

+51
-98
lines changed

eng/Versions.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@
329329
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>
330330
<XUnitRunnerVisualStudioVersion>2.4.3</XUnitRunnerVisualStudioVersion>
331331
<MicrosoftDataSqlClientVersion>4.0.5</MicrosoftDataSqlClientVersion>
332-
<MicrosoftOpenApiVersion>1.6.13</MicrosoftOpenApiVersion>
333-
<MicrosoftOpenApiReadersVersion>1.6.13</MicrosoftOpenApiReadersVersion>
332+
<MicrosoftOpenApiVersion>1.6.17</MicrosoftOpenApiVersion>
333+
<MicrosoftOpenApiReadersVersion>1.6.17</MicrosoftOpenApiReadersVersion>
334334
<!-- dotnet tool versions (see also auto-updated DotnetEfVersion property). -->
335335
<DotnetDumpVersion>6.0.322601</DotnetDumpVersion>
336336
<DotnetServeVersion>1.10.93</DotnetServeVersion>

eng/testing/linker/project.csproj.template

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
1717
<!-- Ensure individual warnings are shown when publishing -->
1818
<TrimmerSingleWarn>false</TrimmerSingleWarn>
19-
<!-- But ignore the single warn files marked below to suppress their known warnings. -->
20-
<NoWarn>$(NoWarn);IL2104</NoWarn>
2119
{AdditionalProperties}
2220
</PropertyGroup>
2321

@@ -29,19 +27,4 @@
2927
{AdditionalProjectReferences}
3028
</ItemGroup>
3129

32-
<!-- Single warn the following assemblies, which have known warnings, so the warnings can be suppressed for now.
33-
Remove this (and the above NoWarn IL2104) once https://github.com/microsoft/OpenAPI.NET/pull/1717 is merged. -->
34-
<Target Name="ConfigureTrimming"
35-
BeforeTargets="PrepareForILLink">
36-
<ItemGroup>
37-
<IlcArg Include="--singlewarnassembly:Microsoft.OpenApi" />
38-
</ItemGroup>
39-
<ItemGroup>
40-
<ManagedAssemblyToLink Condition="'%(Filename)' == 'Microsoft.OpenApi'">
41-
<IsTrimmable>true</IsTrimmable>
42-
<TrimmerSingleWarn>true</TrimmerSingleWarn>
43-
</ManagedAssemblyToLink>
44-
</ItemGroup>
45-
</Target>
46-
4730
</Project>

src/OpenApi/src/Comparers/OpenApiAnyComparer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public bool Equals(IOpenApiAny? x, IOpenApiAny? y)
4242
OpenApiByte byteX => y is OpenApiByte byteY && byteX.Value.SequenceEqual(byteY.Value),
4343
OpenApiDate dateX => y is OpenApiDate dateY && dateX.Value == dateY.Value,
4444
OpenApiDateTime dateTimeX => y is OpenApiDateTime dateTimeY && dateTimeX.Value == dateTimeY.Value,
45-
ScrubbedOpenApiAny scrubbedX => y is ScrubbedOpenApiAny scrubbedY && scrubbedX.Value == scrubbedY.Value,
4645
_ => x.Equals(y)
4746
});
4847
}
@@ -74,7 +73,6 @@ public int GetHashCode(IOpenApiAny obj)
7473
OpenApiPassword password => password.Value,
7574
OpenApiDate date => date.Value,
7675
OpenApiDateTime dateTime => dateTime.Value,
77-
ScrubbedOpenApiAny scrubbed => scrubbed.Value,
7876
_ => null
7977
});
8078

src/OpenApi/src/Comparers/OpenApiSchemaComparer.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,34 @@ public bool Equals(OpenApiSchema? x, OpenApiSchema? y)
6565
x.UniqueItems == y.UniqueItems &&
6666
x.UnresolvedReference == y.UnresolvedReference &&
6767
x.WriteOnly == y.WriteOnly &&
68-
OpenApiXmlComparer.Instance.Equals(x.Xml, y.Xml);
68+
OpenApiXmlComparer.Instance.Equals(x.Xml, y.Xml) &&
69+
SchemaIdEquals(x, y);
70+
}
71+
72+
private static bool SchemaIdEquals(OpenApiSchema x, OpenApiSchema y)
73+
{
74+
if (x.Annotations == null && y.Annotations == null)
75+
{
76+
return true;
77+
}
78+
if (x.Annotations == null || y.Annotations == null)
79+
{
80+
return false;
81+
}
82+
if (x.Annotations.TryGetValue(OpenApiConstants.SchemaId, out var xSchemaId)
83+
&& y.Annotations.TryGetValue(OpenApiConstants.SchemaId, out var ySchemaId))
84+
{
85+
if (xSchemaId == null && ySchemaId == null)
86+
{
87+
return true;
88+
}
89+
if (xSchemaId == null || ySchemaId == null)
90+
{
91+
return false;
92+
}
93+
return xSchemaId.Equals(ySchemaId);
94+
}
95+
return true;
6996
}
7097

7198
public int GetHashCode(OpenApiSchema obj)

src/OpenApi/src/Extensions/OpenApiEndpointRouteBuilderExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Options;
1111
using Microsoft.OpenApi.Extensions;
12+
using Microsoft.OpenApi.Writers;
1213

1314
namespace Microsoft.AspNetCore.Builder;
1415

@@ -48,7 +49,7 @@ public static IEndpointConventionBuilder MapOpenApi(this IEndpointRouteBuilder e
4849
using var writer = Utf8BufferTextWriter.Get(output);
4950
try
5051
{
51-
document.Serialize(new ScrubbingOpenApiJsonWriter(writer), documentOptions.OpenApiVersion);
52+
document.Serialize(new OpenApiJsonWriter(writer), documentOptions.OpenApiVersion);
5253
context.Response.ContentType = "application/json;charset=utf-8";
5354
await context.Response.BodyWriter.WriteAsync(output.ToArray(), context.RequestAborted);
5455
await context.Response.BodyWriter.FlushAsync(context.RequestAborted);

src/OpenApi/src/Schemas/OpenApiJsonSchema.Helpers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ public static void ReadProperty(ref Utf8JsonReader reader, string propertyName,
304304
break;
305305
case OpenApiConstants.SchemaId:
306306
reader.Read();
307-
schema.Extensions.Add(OpenApiConstants.SchemaId, new ScrubbedOpenApiAny(reader.GetString()));
307+
schema.Annotations ??= new Dictionary<string, object>();
308+
schema.Annotations.Add(OpenApiConstants.SchemaId, reader.GetString());
308309
break;
309310
// OpenAPI does not support the `const` keyword in its schema implementation, so
310311
// we map it to its closest approximation, an enum with a single value, here.

src/OpenApi/src/Services/OpenApiDocumentProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.Extensions.Options;
77
using Microsoft.OpenApi;
88
using Microsoft.OpenApi.Extensions;
9+
using Microsoft.OpenApi.Writers;
910
using System.Linq;
1011

1112
namespace Microsoft.Extensions.ApiDescriptions;
@@ -44,7 +45,7 @@ public async Task GenerateAsync(string documentName, TextWriter writer, OpenApiS
4445
// more info.
4546
var targetDocumentService = serviceProvider.GetRequiredKeyedService<OpenApiDocumentService>(documentName);
4647
var document = await targetDocumentService.GetOpenApiDocumentAsync();
47-
var jsonWriter = new ScrubbingOpenApiJsonWriter(writer);
48+
var jsonWriter = new OpenApiJsonWriter(writer);
4849
document.Serialize(jsonWriter, openApiSpecVersion);
4950
}
5051

src/OpenApi/src/Services/OpenApiDocumentService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ internal async Task ForEachOperationAsync(
9999
continue;
100100
}
101101

102-
if (operation.Extensions.TryGetValue(OpenApiConstants.DescriptionId, out var descriptionIdExtension) &&
103-
descriptionIdExtension is ScrubbedOpenApiAny { Value: string descriptionId } &&
104-
TryGetCachedOperationTransformerContext(descriptionId, out var operationContext))
102+
if (operation.Annotations.TryGetValue(OpenApiConstants.DescriptionId, out var descriptionId) &&
103+
descriptionId is string descriptionIdString &&
104+
TryGetCachedOperationTransformerContext(descriptionIdString, out var operationContext))
105105
{
106106
await callback(operation, operationContext, cancellationToken);
107107
}
@@ -169,7 +169,8 @@ private async Task<Dictionary<OperationType, OpenApiOperation>> GetOperationsAsy
169169
foreach (var description in descriptions)
170170
{
171171
var operation = await GetOperationAsync(description, capturedTags, cancellationToken);
172-
operation.Extensions.Add(OpenApiConstants.DescriptionId, new ScrubbedOpenApiAny(description.ActionDescriptor.Id));
172+
operation.Annotations ??= new Dictionary<string, object>();
173+
operation.Annotations.Add(OpenApiConstants.DescriptionId, description.ActionDescriptor.Id);
173174

174175
var operationContext = new OpenApiOperationTransformerContext
175176
{

src/OpenApi/src/Services/Schemas/OpenApiSchemaStore.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ public void PopulateSchemaIntoReferenceCache(OpenApiSchema schema, bool captureS
104104
// AnyOf schemas in a polymorphic type should contain a reference to the parent schema
105105
// ID to support disambiguating between a derived type on its own and a derived type
106106
// as part of a polymorphic schema.
107-
var baseTypeSchemaId = schema.Extensions.TryGetValue(OpenApiConstants.SchemaId, out var schemaId)
108-
? ((ScrubbedOpenApiAny)schemaId).Value
109-
: null;
107+
var baseTypeSchemaId = schema.Annotations is not null && schema.Annotations.TryGetValue(OpenApiConstants.SchemaId, out var schemaId) ? schemaId?.ToString() : null;
110108
foreach (var anyOfSchema in schema.AnyOf)
111109
{
112110
AddOrUpdateSchemaByReference(anyOfSchema, baseTypeSchemaId);
@@ -176,8 +174,8 @@ private void AddOrUpdateSchemaByReference(OpenApiSchema schema, string? baseType
176174

177175
private static string? GetSchemaReferenceId(OpenApiSchema schema)
178176
{
179-
if (schema.Extensions.TryGetValue(OpenApiConstants.SchemaId, out var referenceIdAny)
180-
&& referenceIdAny is ScrubbedOpenApiAny { Value: string referenceId })
177+
if (schema.Annotations?.TryGetValue(OpenApiConstants.SchemaId, out var referenceIdObject) == true
178+
&& referenceIdObject is string referenceId)
181179
{
182180
return referenceId;
183181
}

src/OpenApi/src/Writers/ScrubbedOpenApiAny.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)