Skip to content

feat(securityscheme): add oauth2MetadataUrl support (OpenAPI 3.2)#2706

Merged
baywet merged 12 commits intomicrosoft:mainfrom
mdaneri:feat/oauth2-metadata-url
Feb 19, 2026
Merged

feat(securityscheme): add oauth2MetadataUrl support (OpenAPI 3.2)#2706
baywet merged 12 commits intomicrosoft:mainfrom
mdaneri:feat/oauth2-metadata-url

Conversation

@mdaneri
Copy link
Contributor

@mdaneri mdaneri commented Jan 22, 2026

Pull Request

Description

Adds first-class support for OpenAPI 3.2 oauth2MetadataUrl on OAuth2 security schemes, including serialization and OpenAPI 3.2 reader support.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Related Issue(s)

Fixes #2694

Changes Made

  • Add OAuth2MetadataUrl to OpenApiSecurityScheme/IOpenApiSecurityScheme and reference wrapper.
  • Serialize oauth2MetadataUrl only for OpenAPI 3.2+ when type: oauth2.
  • Parse oauth2MetadataUrl in the OpenAPI 3.2 reader.
  • Add unit tests for serialization and parsing.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Versions applicability

  • My change applies to the version 1.X of the library, if so PR link:
  • My change applies to the version 2.X of the library, if so PR link:
  • My change applies to the version 3.X of the library, if so PR link:
  • I have evaluated the applicability of my change against the other versions above.

Additional Notes

Unit tests executed locally:

  • test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs
  • test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiSecuritySchemeTests.cs

@mdaneri mdaneri requested a review from a team as a code owner January 22, 2026 17:15
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

In addition to the requested change, you'll need to refresh the public API export.

@mdaneri
Copy link
Contributor Author

mdaneri commented Jan 22, 2026

Always I forget about that 😓

@mdaneri
Copy link
Contributor Author

mdaneri commented Jan 22, 2026

That test looks interesting! I might just borrow it and incorporate it into my project.

@baywet
Copy link
Member

baywet commented Jan 22, 2026

That test looks interesting! I might just borrow it and incorporate it into my project.

The dotnet team actually made it an analyzer, so you get feedback on build and not on tests anymore. We just haven't taken the time to update things here. See this as an example.

https://github.com/BinkyLabs/openapi-overlays-dotnet/blob/b9635b903f375498673a3ef801d7d862879e2e3b/src/lib/BinkyLabs.OpenApi.Overlays.csproj#L45

When serializing OAuth2 security schemes, the OAuth2MetadataUrl is now written as 'x-oauth2-metadata-url' for OpenAPI 3.1 and later. Updated tests and public API documentation to reflect this change.
@baywet
Copy link
Member

baywet commented Jan 26, 2026

@mdaneri would you mind updating the benchmarks please?

cd performance/benchmark
dotnet run -c Release

(and commit the changes)

@baywet
Copy link
Member

baywet commented Jan 27, 2026

Hi @mdaneri
I have migrated the repository to use code analyzers in #2711, this should provide earlier feedback (on build instead of on tests) thanks to the warn as errors.
It also means there are conflicts with this PR now, apologies for the additional work.

To drive this to completion, whenever you have time, could you please:

  1. address the comment about the interface split.
  2. rebase (drop the old public APIs for the tests)
  3. update the shipped apis with your changes.

Let me know if you have any additional comments or questions.

@baywet
Copy link
Member

baywet commented Feb 3, 2026

Gentle ping on this one @mdaneri

@mdaneri
Copy link
Contributor Author

mdaneri commented Feb 17, 2026

I'll work on this tomorrow

mdaneri and others added 3 commits February 18, 2026 20:07
…rformance.Descriptions-report-github.md

	modified:   performance/benchmark/BenchmarkDotNet.Artifacts/results/performance.Descriptions-report.csv
	modified:   performance/benchmark/BenchmarkDotNet.Artifacts/results/performance.Descriptions-report.html
	modified:   performance/benchmark/BenchmarkDotNet.Artifacts/results/performance.Descriptions-report.json
	modified:   performance/benchmark/BenchmarkDotNet.Artifacts/results/performance.EmptyModels-report-github.md
	modified:   performance/benchmark/BenchmarkDotNet.Artifacts/results/performance.EmptyModels-report.csv
	modified:   performance/benchmark/BenchmarkDotNet.Artifacts/results/performance.EmptyModels-report.html
	modified:   performance/benchmark/BenchmarkDotNet.Artifacts/results/performance.EmptyModels-report.json
@mdaneri
Copy link
Contributor Author

mdaneri commented Feb 18, 2026

@mdaneri would you mind updating the benchmarks please?

cd performance/benchmark
dotnet run -c Release

(and commit the changes)

Done

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes!
One minor thing to clean up

Remove the IsTrimmable assembly metadata entry from test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt to update the public API baseline to reflect the attribute's removal.
Delete the approved public API snapshot used by tests (test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt). This removes the long approved PublicApi text file, likely because the public API approvals were updated or the snapshot is no longer required; update or regenerate the approved snapshot in tests if needed.
@baywet
Copy link
Member

baywet commented Feb 19, 2026

@mdaneri can you please also run the following:

# add the missing public api entries
dotnet format --diagnostics RS0016
# discard changes to cs files to avoid creating conflicts
git checkout *.cs

and then commit the text file?

Sorry for not providing the context here: I moved this repos from using custom tests for the public API surface to using the "new" dotnet analyzers. And your PR was originally created before that move, hence the "migration" here.

Expose OAuth2 metadata URL support in the public API: add OpenApiConstants.OAuth2MetadataUrl constant, introduce IOAuth2MetadataProvider with an OAuth2MetadataUrl getter (System.Uri?), and surface OAuth2MetadataUrl on OpenApiSecurityScheme (get/set) and OpenApiSecuritySchemeReference (get). This enables consumers to read/write the OAuth2 metadata URL for security schemes.
baywet
baywet previously approved these changes Feb 19, 2026
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes!

@mdaneri
Copy link
Contributor Author

mdaneri commented Feb 19, 2026

Could you please update the contributing guide? It seems like some important information is missing. I’m afraid I might forget all of it next time! :)

@baywet
Copy link
Member

baywet commented Feb 19, 2026

Could you please update the contributing guide? It seems like some important information is missing. I’m afraid I might forget all of it next time! :)

This is an excellent suggestion, working on it.

Also adding this section for the failing benchmarks, would you mind updating them please?

Updating the benchmark information

To ensure performance of the library does not degrade over time, we have continuous benchmarks running. You might see the continuous integration failing if your pull request changed any model under src/Microsoft.OpenApi/Models.

Benchmark result for EmptyApiSchema does not match the existing benchmark result (original!=new). Allocated bytes differ: 408 != 416

To update the benchmarks, run the following script:

cd performance/benchmark
dotnet run -c Release

Then commit the report files using a "chore" commit.

@baywet baywet mentioned this pull request Feb 19, 2026
@baywet
Copy link
Member

baywet commented Feb 19, 2026

also put together #2734 to address the contributing documentation gaps.

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes!

@baywet baywet enabled auto-merge (squash) February 19, 2026 18:38
@baywet baywet merged commit 4509488 into microsoft:main Feb 19, 2026
8 of 9 checks passed
@mdaneri mdaneri deleted the feat/oauth2-metadata-url branch February 19, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI 3.2: oauth2MetadataUrl Missing from Microsoft.OpenApi.OpenApiSecurityScheme

3 participants

Comments