Skip to content

Update Microsoft.OpenApi to preview28 #62363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

captainsafia
Copy link
Member

This pull request primarily updates the Microsoft.OpenApi package versions and refactors code to simplify imports and improve type usage. The most significant changes include updating dependencies, replacing outdated Microsoft.OpenApi.Models types with the new Microsoft.OpenApi namespace, and modifying public API definitions accordingly.

Dependency Updates:

  • Updated MicrosoftOpenApiVersion and MicrosoftOpenApiYamlReaderVersion from 2.0.0-preview.18 to 2.0.0-preview.28 in eng/Versions.props.

Refactoring Imports:

  • Removed references to Microsoft.OpenApi.Models, Microsoft.OpenApi.Models.Interfaces, and Microsoft.OpenApi.Models.References in favor of the new Microsoft.OpenApi namespace across multiple files, including XmlCommentGenerator.Emitter.cs, TransformersBenchmark.cs, and various transformer files in the sample directory. [1] [2] [3] [4] [5] [6] [7]

Code Adjustments:

  • Replaced the initialization of schema.Extensions from an empty array ([]) to a Dictionary<string, IOpenApiExtension> in TransformersBenchmark.cs. [1] [2]

Public API Updates:

  • Updated public API definitions in PublicAPI.Shipped.txt to reflect the transition from Microsoft.OpenApi.Models types to Microsoft.OpenApi types. This includes changes to method signatures and transformer interfaces. [1] [2] [3]

Project Configuration:

  • Added <Using Include="Microsoft.OpenApi" /> to the Sample.csproj and Microsoft.AspNetCore.OpenApi.csproj files to simplify namespace management. [1] [2]

@captainsafia captainsafia requested review from tdykstra, a team and wtgodbe as code owners June 16, 2025 22:19
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Jun 16, 2025
@@ -2,11 +2,11 @@
Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions
Microsoft.AspNetCore.Builder.OpenApiEndpointRouteBuilderExtensions
Microsoft.AspNetCore.OpenApi.IOpenApiDocumentTransformer
Microsoft.AspNetCore.OpenApi.IOpenApiDocumentTransformer.TransformAsync(Microsoft.OpenApi.Models.OpenApiDocument! document, Microsoft.AspNetCore.OpenApi.OpenApiDocumentTransformerContext! context, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
Copy link
Member

Choose a reason for hiding this comment

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

Don't touch this file

Copy link
Member Author

Choose a reason for hiding this comment

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

The codefixer for the PublicAPI analyzer applied this delta. Although I think it just reveals an underlying bug in the way the PublicAPI analyzer works? In this case, the same types for existing APIs have been moved to new namespaces. Maybe the delta here is to remove all the old APIs and then add the new ones?

Copy link
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

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

Breaking change announcement probably needed for API changing?

@@ -98,7 +97,8 @@ public static Task Verify(string source, IIncrementalGenerator generator, Dictio
.ScrubLinesWithReplace(line => InterceptsLocationRegex().Replace(line, "[InterceptsLocation]"))
.UseDirectory(SkipOnHelixAttribute.OnHelix()
? Path.Combine(Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"), "snapshots")
: "snapshots");
: "snapshots")
.AutoVerify();
Copy link
Member

Choose a reason for hiding this comment

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

Remove

@@ -38,6 +36,7 @@ public async Task VerifyOpenApiDocument(string documentName, OpenApiSpecVersion
var outputDirectory = Path.Combine(baseSnapshotsDirectory, version.ToString());
await Verifier.Verify(json)
.UseDirectory(outputDirectory)
.UseParameters(documentName);
.UseParameters(documentName)
.AutoVerify();
Copy link
Member

Choose a reason for hiding this comment

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

Remove

using Microsoft.OpenApi;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Writers;

Copy link
Member

Choose a reason for hiding this comment

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

rm

@@ -140,10 +137,11 @@ internal async Task<OpenApiSchema> GetOrCreateUnresolvedSchemaAsync(OpenApiDocum
internal async Task<IOpenApiSchema> GetOrCreateSchemaAsync(OpenApiDocument document, Type type, IServiceProvider scopedServiceProvider, IOpenApiSchemaTransformer[] schemaTransformers, ApiParameterDescription? parameterDescription = null, CancellationToken cancellationToken = default)
{
var schema = await GetOrCreateUnresolvedSchemaAsync(document, type, scopedServiceProvider, schemaTransformers, parameterDescription, cancellationToken);
return ResolveReferenceForSchema(document, schema);
var baseSchemaId = optionsMonitor.Get(documentName).CreateSchemaReferenceId(_jsonSerializerOptions.GetTypeInfo(type));
Copy link
Member

Choose a reason for hiding this comment

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

Is this expensive? Do we care?

@@ -712,18 +708,15 @@ await VerifyOpenApiDocument(builder, document =>

// Assert items are arrays of strings
Assert.Equal(JsonSchemaType.Array, seq1Schema.Items.Type);
// Todo: See https://github.com/microsoft/OpenAPI.NET/issues/2062
// Assert.Equal(JsonSchemaType.Array, seq2Schema.Items.Type);
Assert.Equal(JsonSchemaType.Array, seq2Schema.Items.Type);
Copy link
Member

Choose a reason for hiding this comment

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

👍

{
return document.AddOpenApiSchemaByReference(schemaIdString, schema);
}
var relativeSchemaId = $"#/components/schemas/{rootSchemaId}{refIdString.Replace("#", string.Empty)}";
Copy link
Member

Choose a reason for hiding this comment

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

Is this where the tags and items updates in the tests comes from?

Do we want to add any explicit testing here?

@martincostello
Copy link
Member

Breaking change announcement probably needed for API changing?

Comparing main vs this PR, there's already a tonne of breaking changes via Microsoft.OpenApi in already shipped previews of 10. This is just even more churn on top of what we've had already 😅.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants