Skip to content

Commit

Permalink
Upgrade to Microsoft.OpenApi 2.x and support OpenAPI v3.1 (#59480)
Browse files Browse the repository at this point in the history
* Upgrade to Microsoft.OpenApi 2.x and support OpenAPI v3.1

* Update usage in GetDocumentInsider

* Fix packaging and AoT tests

* Update AoT test project exemptions

* Address feedback

* Try ignoring whitespace

* Update to 2.0.0-preview.6
  • Loading branch information
captainsafia committed Feb 11, 2025
1 parent 13d7659 commit 898c720
Show file tree
Hide file tree
Showing 61 changed files with 1,171 additions and 2,712 deletions.
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@
<XunitExtensibilityExecutionVersion>$(XunitVersion)</XunitExtensibilityExecutionVersion>
<XUnitRunnerVisualStudioVersion>2.8.2</XUnitRunnerVisualStudioVersion>
<MicrosoftDataSqlClientVersion>5.2.2</MicrosoftDataSqlClientVersion>
<MicrosoftOpenApiVersion>1.6.17</MicrosoftOpenApiVersion>
<MicrosoftOpenApiReadersVersion>1.6.17</MicrosoftOpenApiReadersVersion>
<MicrosoftOpenApiVersion>2.0.0-preview4</MicrosoftOpenApiVersion>
<MicrosoftOpenApiReadersVersion>2.0.0-preview4</MicrosoftOpenApiReadersVersion>
<!-- dotnet tool versions (see also auto-updated DotnetEfVersion property). -->
<DotnetDumpVersion>6.0.322601</DotnetDumpVersion>
<DotnetServeVersion>1.10.93</DotnetServeVersion>
Expand Down
17 changes: 17 additions & 0 deletions eng/testing/linker/project.csproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<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;IL3053</NoWarn>
{AdditionalProperties}
</PropertyGroup>

Expand All @@ -27,4 +29,19 @@
{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/issues/1875 is addressed. -->
<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>
63 changes: 0 additions & 63 deletions src/OpenApi/perf/Microbenchmarks/OpenApiSchemaComparerBenchmark.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/OpenApi/perf/Microbenchmarks/TransformersBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()!.ToLowerInvariant())}");

schema.ExternalDocs = new OpenApiExternalDocs
{
Expand Down
3 changes: 1 addition & 2 deletions src/OpenApi/sample/Transformers/OperationTransformers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
{
Expand Down
95 changes: 0 additions & 95 deletions src/OpenApi/src/Comparers/ComparerHelpers.cs

This file was deleted.

117 changes: 0 additions & 117 deletions src/OpenApi/src/Comparers/OpenApiAnyComparer.cs

This file was deleted.

Loading

0 comments on commit 898c720

Please sign in to comment.