@@ -93,6 +93,24 @@ public class OpenApiSecuritySchemeTests
9393 }
9494 } ;
9595
96+ private static OpenApiSecurityScheme OAuth2MetadataSecurityScheme => new ( )
97+ {
98+ Description = "description1" ,
99+ Type = SecuritySchemeType . OAuth2 ,
100+ OAuth2MetadataUrl = new ( "https://idp.example.com/.well-known/oauth-authorization-server" ) ,
101+ Flows = new ( )
102+ {
103+ ClientCredentials = new ( )
104+ {
105+ TokenUrl = new ( "https://idp.example.com/oauth/token" ) ,
106+ Scopes = new Dictionary < string , string >
107+ {
108+ [ "scope:one" ] = "Scope one"
109+ }
110+ }
111+ }
112+ } ;
113+
96114 private static OpenApiSecurityScheme OpenIdConnectSecurityScheme => new ( )
97115 {
98116 Description = "description1" ,
@@ -257,6 +275,61 @@ public async Task SerializeOAuthSingleFlowSecuritySchemeAsV3JsonWorks()
257275 Assert . Equal ( expected , actual ) ;
258276 }
259277
278+ [ Fact ]
279+ public async Task SerializeOAuthSecuritySchemeWithMetadataUrlAsV32JsonWorks ( )
280+ {
281+ // Arrange
282+ var expected =
283+ """
284+ {
285+ "type": "oauth2",
286+ "description": "description1",
287+ "oauth2MetadataUrl": "https://idp.example.com/.well-known/oauth-authorization-server",
288+ "flows": {
289+ "clientCredentials": {
290+ "tokenUrl": "https://idp.example.com/oauth/token",
291+ "scopes": {
292+ "scope:one": "Scope one"
293+ }
294+ }
295+ }
296+ }
297+ """ ;
298+
299+ // Act
300+ var actual = await OAuth2MetadataSecurityScheme . SerializeAsJsonAsync ( OpenApiSpecVersion . OpenApi3_2 ) ;
301+
302+ // Assert
303+ Assert . True ( JsonNode . DeepEquals ( JsonNode . Parse ( expected ) , JsonNode . Parse ( actual ) ) ) ;
304+ }
305+
306+ [ Fact ]
307+ public async Task SerializeOAuthSecuritySchemeWithMetadataUrlAsV31JsonOmitsMetadataUrl ( )
308+ {
309+ // Arrange
310+ var expected =
311+ """
312+ {
313+ "type": "oauth2",
314+ "description": "description1",
315+ "flows": {
316+ "clientCredentials": {
317+ "tokenUrl": "https://idp.example.com/oauth/token",
318+ "scopes": {
319+ "scope:one": "Scope one"
320+ }
321+ }
322+ }
323+ }
324+ """ ;
325+
326+ // Act
327+ var actual = await OAuth2MetadataSecurityScheme . SerializeAsJsonAsync ( OpenApiSpecVersion . OpenApi3_1 ) ;
328+
329+ // Assert
330+ Assert . True ( JsonNode . DeepEquals ( JsonNode . Parse ( expected ) , JsonNode . Parse ( actual ) ) ) ;
331+ }
332+
260333 [ Fact ]
261334 public async Task SerializeOAuthMultipleFlowSecuritySchemeAsV3JsonWorks ( )
262335 {
0 commit comments