Skip to content

Commit 691d99d

Browse files
author
Iván Canales Martín
committed
Add null check to OpenApiDocument.Components
Without a null check this method will fail if the optional components field is missing.
1 parent 598f2b6 commit 691d99d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public static class OpenApiFilterService
6161
public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Func<string, OperationType?, OpenApiOperation, bool> predicate)
6262
{
6363
// Fetch and copy title, graphVersion and server info from OpenApiDoc
64+
var components = source.Components is null
65+
? null
66+
: new OpenApiComponents() { SecuritySchemes = source.Components.SecuritySchemes };
67+
6468
var subset = new OpenApiDocument
6569
{
6670
Info = new()
@@ -74,7 +78,7 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun
7478
Extensions = source.Info.Extensions
7579
},
7680

77-
Components = new() { SecuritySchemes = source.Components.SecuritySchemes },
81+
Components = components,
7882
SecurityRequirements = source.SecurityRequirements,
7983
Servers = source.Servers
8084
};

0 commit comments

Comments
 (0)