Skip to content

Commit 14b73bf

Browse files
committed
Add x-oauth2-metadata-url serialization for OAuth2 schemes
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.
1 parent 335cee5 commit 14b73bf

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/Microsoft.OpenApi/Models/OpenApiSecurityScheme.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
128128
{
129129
writer.WriteProperty(OpenApiConstants.OAuth2MetadataUrl, OAuth2MetadataUrl?.ToString());
130130
}
131+
else
132+
{
133+
writer.WriteProperty("x-oauth2-metadata-url", OAuth2MetadataUrl?.ToString());
134+
}
131135
writer.WriteOptionalObject(OpenApiConstants.Flows, Flows, callback);
132136
break;
133137
case SecuritySchemeType.OpenIdConnect:

test/Microsoft.OpenApi.Tests/Models/OpenApiSecuritySchemeTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ public async Task SerializeOAuthSecuritySchemeWithMetadataUrlAsV31JsonOmitsMetad
312312
{
313313
"type": "oauth2",
314314
"description": "description1",
315+
"x-oauth2-metadata-url": "https://idp.example.com/.well-known/oauth-authorization-server",
315316
"flows": {
316317
"clientCredentials": {
317318
"tokenUrl": "https://idp.example.com/oauth/token",

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ namespace Microsoft.OpenApi
288288
Microsoft.OpenApi.OpenApiOAuthFlows? Flows { get; }
289289
Microsoft.OpenApi.ParameterLocation? In { get; }
290290
string? Name { get; }
291+
System.Uri? OAuth2MetadataUrl { get; }
291292
System.Uri? OpenIdConnectUrl { get; }
292293
string? Scheme { get; }
293294
Microsoft.OpenApi.SecuritySchemeType? Type { get; }
@@ -538,6 +539,7 @@ namespace Microsoft.OpenApi
538539
public const string Null = "null";
539540
public const string Nullable = "nullable";
540541
public const string NullableExtension = "x-nullable";
542+
public const string OAuth2MetadataUrl = "oauth2MetadataUrl";
541543
public const string OneOf = "oneOf";
542544
public const string OpenApi = "openapi";
543545
public const string OpenIdConnectUrl = "openIdConnectUrl";
@@ -1381,6 +1383,7 @@ namespace Microsoft.OpenApi
13811383
public Microsoft.OpenApi.OpenApiOAuthFlows? Flows { get; set; }
13821384
public Microsoft.OpenApi.ParameterLocation? In { get; set; }
13831385
public string? Name { get; set; }
1386+
public System.Uri? OAuth2MetadataUrl { get; set; }
13841387
public System.Uri? OpenIdConnectUrl { get; set; }
13851388
public string? Scheme { get; set; }
13861389
public Microsoft.OpenApi.SecuritySchemeType? Type { get; set; }
@@ -1400,6 +1403,7 @@ namespace Microsoft.OpenApi
14001403
public Microsoft.OpenApi.OpenApiOAuthFlows? Flows { get; }
14011404
public Microsoft.OpenApi.ParameterLocation? In { get; }
14021405
public string? Name { get; }
1406+
public System.Uri? OAuth2MetadataUrl { get; }
14031407
public System.Uri? OpenIdConnectUrl { get; }
14041408
public string? Scheme { get; }
14051409
public Microsoft.OpenApi.SecuritySchemeType? Type { get; }

0 commit comments

Comments
 (0)