-
Notifications
You must be signed in to change notification settings - Fork 283
feat(securityscheme): add oauth2MetadataUrl support (OpenAPI 3.2) #2706
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
base: main
Are you sure you want to change the base?
Conversation
baywet
left a comment
There was a problem hiding this 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.
|
Always I forget about that 😓 |
|
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. |
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.
| Microsoft.OpenApi.OpenApiOAuthFlows? Flows { get; } | ||
| Microsoft.OpenApi.ParameterLocation? In { get; } | ||
| string? Name { get; } | ||
| System.Uri? OAuth2MetadataUrl { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is technically source breaking. Even though we recommend not to take a dependency on those interfaces. This still poses a problem with the transitive dependency aspect of things. I.E. if a dependency like aspnetcore.openapi or swashbuckle is accessing other properties in the DOM of type IOpenApiSecurityScheme and have not re-compiled after we ship that change, they'll get exceptions like MethodNotFound/ or that the interface is not implemented by the types that actually implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One way we could try to mitigate this is through Default Interface Implementations, but they are only supported for net core 3.0 onwards. And we currently ship netstandard2.0 and net8.0. We'd need to figure out something for netstandard2.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And even if we added the default implementation, it'd still remain binary breaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This effectively leaves us with the following choices:
- major rev, and the cost associated with supporting v3.
- major rev, and not support v3, only a valid approach as long as net11 does not have support for v3. And we should ensure we don't have any other breaking changes that need to be slated.
- decline this PR, and have an incomplete DOM.
- revert the interface change, but keep the rest. That degrades the experience quite a bit forcing type assertions/casts to access the property. And we'd clean this up in a future major version (OpenAPI 3.3?)
- introduce an additional interface to facilitate the type assertions. (variation of the above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @martincostello in case you have a better suggestion here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduce this via a new interface instead?
Thinking out loud, you could add an IOAuth2MetadataProvider interface:
public interface IOAuth2MetadataProvider
{
Uri? OAuth2MetadataUrl { get; }
}Then implement that interface on whatever concrete types need it, and require users to type cast to test for it for implementations that care about it:
if (thing is IOAuth2MetadataProvider oauth2Metadata)
{
// whatever
}As already noted, adding it to other interfaces in their inheritance chain is source breaking and DIMs are problematic for TFMs that are too old to support it (i.e. for .NET Framework via netstandard2.0).
You could potentially avoid that by making the new interface conditionally compiled for #if NET and use DIMs, but that would make the API surface non-symmetrical for different TFMs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the additional information.
Yes that was the last option I was listing even though I didn't explicitly document it. Let's go with that then.
@mdaneri, would you mind introducing a new interface please? Additionally please:
- leave a super explicit doc comment this is a "temporary" interface.
- leave a todo comment to remove and collapse the interface with the existing one on the next major version.
- update the doc comment of the existing interface to point to this one. Example with type assertions would be nice as well. So people are not surprised by this pattern, know that's mostly because we (Microsoft) messed up, and know where to find the missing property.
|
@mdaneri would you mind updating the benchmarks please? cd performance/benchmark
dotnet run -c Release(and commit the changes) |
Pull Request
Description
Adds first-class support for OpenAPI 3.2
oauth2MetadataUrlon OAuth2 security schemes, including serialization and OpenAPI 3.2 reader support.Type of Change
Related Issue(s)
Fixes #2694
Changes Made
OAuth2MetadataUrltoOpenApiSecurityScheme/IOpenApiSecuritySchemeand reference wrapper.oauth2MetadataUrlonly for OpenAPI 3.2+ whentype: oauth2.oauth2MetadataUrlin the OpenAPI 3.2 reader.Testing
Checklist
Versions applicability
Additional Notes
Unit tests executed locally:
test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cstest/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiSecuritySchemeTests.cs