Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>
<XUnitRunnerVisualStudioVersion>2.4.3</XUnitRunnerVisualStudioVersion>
<MicrosoftDataSqlClientVersion>4.0.5</MicrosoftDataSqlClientVersion>
<MicrosoftOpenApiVersion>1.6.13</MicrosoftOpenApiVersion>
<MicrosoftOpenApiReadersVersion>1.6.13</MicrosoftOpenApiReadersVersion>
<MicrosoftOpenApiVersion>1.6.17</MicrosoftOpenApiVersion>
<MicrosoftOpenApiReadersVersion>1.6.17</MicrosoftOpenApiReadersVersion>
<!-- dotnet tool versions (see also auto-updated DotnetEfVersion property). -->
<DotnetDumpVersion>6.0.322601</DotnetDumpVersion>
<DotnetServeVersion>1.10.93</DotnetServeVersion>
Expand Down
17 changes: 0 additions & 17 deletions eng/testing/linker/project.csproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
<!-- Ensure individual warnings are shown when publishing -->
<TrimmerSingleWarn>false</TrimmerSingleWarn>
<!-- But ignore the single warn files marked below to suppress their known warnings. -->
<NoWarn>$(NoWarn);IL2104</NoWarn>
{AdditionalProperties}
</PropertyGroup>

Expand All @@ -29,19 +27,4 @@
{AdditionalProjectReferences}
</ItemGroup>

<!-- Single warn the following assemblies, which have known warnings, so the warnings can be suppressed for now.
Remove this (and the above NoWarn IL2104) once https://github.com/microsoft/OpenAPI.NET/pull/1717 is merged. -->
Copy link
Member

Choose a reason for hiding this comment

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

🥳

<Target Name="ConfigureTrimming"
BeforeTargets="PrepareForILLink">
<ItemGroup>
<IlcArg Include="--singlewarnassembly:Microsoft.OpenApi" />
</ItemGroup>
<ItemGroup>
<ManagedAssemblyToLink Condition="'%(Filename)' == 'Microsoft.OpenApi'">
<IsTrimmable>true</IsTrimmable>
<TrimmerSingleWarn>true</TrimmerSingleWarn>
</ManagedAssemblyToLink>
</ItemGroup>
</Target>

</Project>
2 changes: 0 additions & 2 deletions src/OpenApi/src/Comparers/OpenApiAnyComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public bool Equals(IOpenApiAny? x, IOpenApiAny? y)
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,
ScrubbedOpenApiAny scrubbedX => y is ScrubbedOpenApiAny scrubbedY && scrubbedX.Value == scrubbedY.Value,
_ => x.Equals(y)
});
}
Expand Down Expand Up @@ -74,7 +73,6 @@ public int GetHashCode(IOpenApiAny obj)
OpenApiPassword password => password.Value,
OpenApiDate date => date.Value,
OpenApiDateTime dateTime => dateTime.Value,
ScrubbedOpenApiAny scrubbed => scrubbed.Value,
_ => null
});

Expand Down
29 changes: 28 additions & 1 deletion src/OpenApi/src/Comparers/OpenApiSchemaComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,34 @@ public bool Equals(OpenApiSchema? x, OpenApiSchema? y)
x.UniqueItems == y.UniqueItems &&
x.UnresolvedReference == y.UnresolvedReference &&
x.WriteOnly == y.WriteOnly &&
OpenApiXmlComparer.Instance.Equals(x.Xml, y.Xml);
OpenApiXmlComparer.Instance.Equals(x.Xml, y.Xml) &&
SchemaIdEquals(x, y);
}

private static bool SchemaIdEquals(OpenApiSchema x, OpenApiSchema y)
{
if (x.Annotations == null && y.Annotations == null)
{
return true;
}
if (x.Annotations == null || y.Annotations == null)
{
return false;
}
if (x.Annotations.TryGetValue(OpenApiConstants.SchemaId, out var xSchemaId)
&& y.Annotations.TryGetValue(OpenApiConstants.SchemaId, out var ySchemaId))
{
if (xSchemaId == null && ySchemaId == null)
{
return true;
}
if (xSchemaId == null || ySchemaId == null)
{
return false;
}
return xSchemaId.Equals(ySchemaId);
}
return true;
}

public int GetHashCode(OpenApiSchema obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Writers;

namespace Microsoft.AspNetCore.Builder;

Expand Down Expand Up @@ -48,7 +49,7 @@ public static IEndpointConventionBuilder MapOpenApi(this IEndpointRouteBuilder e
using var writer = Utf8BufferTextWriter.Get(output);
try
{
document.Serialize(new ScrubbingOpenApiJsonWriter(writer), documentOptions.OpenApiVersion);
document.Serialize(new OpenApiJsonWriter(writer), documentOptions.OpenApiVersion);
context.Response.ContentType = "application/json;charset=utf-8";
await context.Response.BodyWriter.WriteAsync(output.ToArray(), context.RequestAborted);
await context.Response.BodyWriter.FlushAsync(context.RequestAborted);
Expand Down
3 changes: 2 additions & 1 deletion src/OpenApi/src/Schemas/OpenApiJsonSchema.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ public static void ReadProperty(ref Utf8JsonReader reader, string propertyName,
break;
case OpenApiConstants.SchemaId:
reader.Read();
schema.Extensions.Add(OpenApiConstants.SchemaId, new ScrubbedOpenApiAny(reader.GetString()));
schema.Annotations ??= new Dictionary<string, object>();
schema.Annotations.Add(OpenApiConstants.SchemaId, reader.GetString());
break;
// OpenAPI does not support the `const` keyword in its schema implementation, so
// we map it to its closest approximation, an enum with a single value, here.
Expand Down
3 changes: 2 additions & 1 deletion src/OpenApi/src/Services/OpenApiDocumentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Extensions.Options;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Writers;
using System.Linq;

namespace Microsoft.Extensions.ApiDescriptions;
Expand Down Expand Up @@ -44,7 +45,7 @@ public async Task GenerateAsync(string documentName, TextWriter writer, OpenApiS
// more info.
var targetDocumentService = serviceProvider.GetRequiredKeyedService<OpenApiDocumentService>(documentName);
var document = await targetDocumentService.GetOpenApiDocumentAsync();
var jsonWriter = new ScrubbingOpenApiJsonWriter(writer);
var jsonWriter = new OpenApiJsonWriter(writer);
document.Serialize(jsonWriter, openApiSpecVersion);
}

Expand Down
9 changes: 5 additions & 4 deletions src/OpenApi/src/Services/OpenApiDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ internal async Task ForEachOperationAsync(
continue;
}

if (operation.Extensions.TryGetValue(OpenApiConstants.DescriptionId, out var descriptionIdExtension) &&
descriptionIdExtension is ScrubbedOpenApiAny { Value: string descriptionId } &&
TryGetCachedOperationTransformerContext(descriptionId, out var operationContext))
if (operation.Annotations.TryGetValue(OpenApiConstants.DescriptionId, out var descriptionId) &&
descriptionId is string descriptionIdString &&
TryGetCachedOperationTransformerContext(descriptionIdString, out var operationContext))
{
await callback(operation, operationContext, cancellationToken);
}
Expand Down Expand Up @@ -169,7 +169,8 @@ private async Task<Dictionary<OperationType, OpenApiOperation>> GetOperationsAsy
foreach (var description in descriptions)
{
var operation = await GetOperationAsync(description, capturedTags, cancellationToken);
operation.Extensions.Add(OpenApiConstants.DescriptionId, new ScrubbedOpenApiAny(description.ActionDescriptor.Id));
operation.Annotations ??= new Dictionary<string, object>();
operation.Annotations.Add(OpenApiConstants.DescriptionId, description.ActionDescriptor.Id);

var operationContext = new OpenApiOperationTransformerContext
{
Expand Down
8 changes: 3 additions & 5 deletions src/OpenApi/src/Services/Schemas/OpenApiSchemaStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ public void PopulateSchemaIntoReferenceCache(OpenApiSchema schema, bool captureS
// AnyOf schemas in a polymorphic type should contain a reference to the parent schema
// ID to support disambiguating between a derived type on its own and a derived type
// as part of a polymorphic schema.
var baseTypeSchemaId = schema.Extensions.TryGetValue(OpenApiConstants.SchemaId, out var schemaId)
? ((ScrubbedOpenApiAny)schemaId).Value
: null;
var baseTypeSchemaId = schema.Annotations is not null && schema.Annotations.TryGetValue(OpenApiConstants.SchemaId, out var schemaId) ? schemaId?.ToString() : null;
foreach (var anyOfSchema in schema.AnyOf)
{
AddOrUpdateSchemaByReference(anyOfSchema, baseTypeSchemaId);
Expand Down Expand Up @@ -176,8 +174,8 @@ private void AddOrUpdateSchemaByReference(OpenApiSchema schema, string? baseType

private static string? GetSchemaReferenceId(OpenApiSchema schema)
{
if (schema.Extensions.TryGetValue(OpenApiConstants.SchemaId, out var referenceIdAny)
&& referenceIdAny is ScrubbedOpenApiAny { Value: string referenceId })
if (schema.Annotations?.TryGetValue(OpenApiConstants.SchemaId, out var referenceIdObject) == true
&& referenceIdObject is string referenceId)
{
return referenceId;
}
Expand Down
30 changes: 0 additions & 30 deletions src/OpenApi/src/Writers/ScrubbedOpenApiAny.cs

This file was deleted.

30 changes: 0 additions & 30 deletions src/OpenApi/src/Writers/ScrubbingOpenApiJsonWriter.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public class OpenApiAnyComparerTests
[new OpenApiArray { new OpenApiString("value") }, new OpenApiArray { new OpenApiString("value2") }, false],
[new OpenApiArray { new OpenApiString("value2"), new OpenApiString("value") }, new OpenApiArray { new OpenApiString("value"), new OpenApiString("value2") }, false],
[new OpenApiArray { new OpenApiString("value"), new OpenApiString("value") }, new OpenApiArray { new OpenApiString("value"), new OpenApiString("value") }, true],
[new ScrubbedOpenApiAny("value"), new ScrubbedOpenApiAny("value"), true],
[new ScrubbedOpenApiAny("value"), new ScrubbedOpenApiAny("value2"), false],
[new ScrubbedOpenApiAny(null), new ScrubbedOpenApiAny(null), true]
];

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void ValidatePropertiesOnOpenApiSchema()
UnresolvedReference = true,
WriteOnly = true,
Xml = new OpenApiXml { Name = "Name" },
Annotations = new Dictionary<string, object> { ["key"] = "value" }
};

OpenApiSchema modifiedSchema = new(originalSchema) { AdditionalProperties = new OpenApiSchema { Type = "string" } };
Expand Down Expand Up @@ -302,6 +303,11 @@ public void ValidatePropertiesOnOpenApiSchema()
Assert.False(OpenApiSchemaComparer.Instance.Equals(originalSchema, modifiedSchema));
Assert.True(propertyNames.Remove(nameof(OpenApiSchema.Xml)));

modifiedSchema = new(originalSchema);
modifiedSchema.Annotations["key"] = "another value";
Assert.False(OpenApiSchemaComparer.Instance.Equals(originalSchema, modifiedSchema));
Assert.True(propertyNames.Remove(nameof(OpenApiSchema.Annotations)));

Assert.Empty(propertyNames);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ await Verifier.Verify(GetOpenApiJson(document))
private static string GetOpenApiJson(OpenApiDocument document)
{
using var textWriter = new StringWriter(CultureInfo.InvariantCulture);
var jsonWriter = new ScrubbingOpenApiJsonWriter(textWriter);
var jsonWriter = new OpenApiJsonWriter(textWriter);
document.SerializeAsV3(jsonWriter);
return textWriter.ToString();
}
Expand Down