Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@martincostello
Copy link
Member

@martincostello martincostello commented Nov 14, 2025

Update Microsoft.OpenApi to 3.0.0

Update Microsoft.OpenApi to 3.0.0 for basic OpenAPI 3.2 support.

Description

Update to [email protected] to add basic support for OpenAPI 3.2 and fix compilation errors when trying to use v3 in an ASP.NET Core application.

I'm not sure what exact other changes may be required for full OpenAPI 3.2 compatibility at this stage, but this at least resolves the runtime errors when using Microsoft.OpenApi 3.0.0.

One change that needs some thought is for example that HTTP QUERY is now supported in OpenAPI 3.2:

public static HttpMethod? GetHttpMethod(this ApiDescription apiDescription) =>
apiDescription.HttpMethod?.ToUpperInvariant() switch
{
// Only add methods documented in the OpenAPI spec: https://spec.openapis.org/oas/v3.1.1.html#path-item-object
"GET" => HttpMethod.Get,
"POST" => HttpMethod.Post,
"PUT" => HttpMethod.Put,
"DELETE" => HttpMethod.Delete,
"PATCH" => HttpMethod.Patch,
"HEAD" => HttpMethod.Head,
"OPTIONS" => HttpMethod.Options,
"TRACE" => HttpMethod.Trace,
_ => null,
};

It's trivial enough to extend this method to handle QUERY, but then how do we skip it here when the document is going to be serialized in a version that's too low to allow it?

if (description.GetHttpMethod() is not { } method)
{
// Skip unsupported HTTP methods
continue;
}

It also appears that both swagger-ui and redoc don't yet support OpenAPI 3.2:

Contributes to #64317.

Update to `[email protected]` to add basic support for OpenAPI 3.2 and fix compilation errors.

Relates to dotnet#64317.
Copilot AI review requested due to automatic review settings November 14, 2025 15:15
@martincostello martincostello marked this pull request as draft November 14, 2025 15:15
@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 Nov 14, 2025
@martincostello martincostello removed the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Nov 14, 2025
@martincostello martincostello added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc labels Nov 14, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 14, 2025
@dotnet-policy-service
Copy link
Contributor

Thanks for your PR, @@martincostello. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copilot finished reviewing on behalf of martincostello November 14, 2025 15:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the Microsoft.OpenApi package from version 2.0.0 to 3.0.0 to add basic support for OpenAPI 3.2 and resolve runtime errors when using the updated library in ASP.NET Core applications.

  • Updated Microsoft.OpenApi and Microsoft.OpenApi.YamlReader package versions to 3.0.0
  • Changed dictionary types from Dictionary<string, OpenApiMediaType> to Dictionary<string, IOpenApiMediaType> to match the new API
  • Added defensive type checking when accessing media type properties
  • Added OpenAPI 3.2 spec version support and corresponding test snapshots

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated no comments.

Show a summary per file
File Description
eng/Versions.props Updated Microsoft.OpenApi and Microsoft.OpenApi.YamlReader from 2.0.0 to 3.0.0
src/OpenApi/src/Services/OpenApiDocumentService.cs Changed Content dictionary type from OpenApiMediaType to IOpenApiMediaType
src/OpenApi/src/Services/OpenApiGenerator.cs Changed Content dictionary type from OpenApiMediaType to IOpenApiMediaType
src/OpenApi/gen/XmlCommentGenerator.Emitter.cs Added type checking when setting Example property on media types
src/OpenApi/test/.../CustomSchemaTransformerTests.cs Updated test code to use IOpenApiMediaType interface
src/OpenApi/test/.../OpenApiDocumentIntegrationTests.cs Added OpenApi3_2 spec version to test data
src/OpenApi/test/.../OpenApiEndpointRouteBuilderExtensionsTests.cs Updated OpenAPI version string from 3.1.1 to 3.1.2 in assertions
src/OpenApi/test/.../snapshots/OpenApi3_1/*.verified.txt Updated OpenAPI version from 3.1.1 to 3.1.2 in snapshot files
src/OpenApi/test/.../snapshots/OpenApi3_2/*.verified.txt Added new snapshot files for OpenAPI 3.2.0 spec version
src/OpenApi/test/.../snapshots/*#OpenApiXmlCommentSupport.generated.verified.cs Added type checking when setting Example property in generated code
src/OpenApi/test/.../OpenApiDocumentLocalizationTests.VerifyOpenApiDocumentIsInvariant.verified.txt Updated OpenAPI version from 3.1.1 to 3.1.2

@desjoerd
Copy link
Contributor

I'm not sure what exact other changes may be required for full OpenAPI 3.2 compatibility at this stage, but this at least resolves the runtime errors when using Microsoft.OpenApi 3.0.0.

When looking through the OpenAPI 3.1 to 3.2 steps https://learn.openapis.org/upgrading/v3.1-to-v3.2#migration-checklist and going through the spec, it doesn't look like there are any real breaking changes. So it really looks like a real minor release 😎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc community-contribution Indicates that the PR has been added by a community member feature-openapi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants