Skip to content

Commit b39303e

Browse files
committed
Retrieve missing path parameters during slicing
1 parent 6a3e948 commit b39303e

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ public static OpenApiDocument CreateFilteredDocument(OpenApiDocument source, Fun
164164
if (result.CurrentKeys.Operation != null)
165165
{
166166
pathItem.Operations.Add((OperationType)result.CurrentKeys.Operation, result.Operation);
167+
168+
if (result.Parameters?.Any() ?? false)
169+
{
170+
foreach (var parameter in result.Parameters)
171+
{
172+
pathItem.Parameters.Add(parameter);
173+
}
174+
}
167175
}
168176
}
169177

src/Microsoft.OpenApi/Services/OperationSearch.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,25 @@ public OperationSearch(Func<string, OperationType?,OpenApiOperation, bool> predi
3131
}
3232

3333
/// <summary>
34-
/// Visits <see cref="OpenApiOperation"/>.
34+
/// Visits <see cref="OpenApiPathItem"/>
3535
/// </summary>
36-
/// <param name="operation">The target <see cref="OpenApiOperation"/>.</param>
37-
public override void Visit(OpenApiOperation operation)
36+
/// <param name="pathItem"> The target <see cref="OpenApiPathItem"/>.</param>
37+
public override void Visit(OpenApiPathItem pathItem)
3838
{
39-
if (_predicate(CurrentKeys.Path, CurrentKeys.Operation, operation))
39+
foreach (var item in pathItem.Operations)
4040
{
41-
_searchResults.Add(new SearchResult()
41+
var operation = item.Value;
42+
var operationType = item.Key;
43+
44+
if (_predicate(CurrentKeys.Path, CurrentKeys.Operation, operation))
4245
{
43-
Operation = operation,
44-
CurrentKeys = CopyCurrentKeys(CurrentKeys)
45-
});
46+
_searchResults.Add(new SearchResult()
47+
{
48+
Operation = operation,
49+
Parameters = pathItem.Parameters,
50+
CurrentKeys = CopyCurrentKeys(CurrentKeys, operationType)
51+
});
52+
}
4653
}
4754
}
4855

@@ -65,12 +72,12 @@ public override void Visit(IList<OpenApiParameter> parameters)
6572
base.Visit(parameters);
6673
}
6774

68-
private static CurrentKeys CopyCurrentKeys(CurrentKeys currentKeys)
75+
private static CurrentKeys CopyCurrentKeys(CurrentKeys currentKeys, OperationType operationType)
6976
{
7077
return new CurrentKeys
7178
{
7279
Path = currentKeys.Path,
73-
Operation = currentKeys.Operation
80+
Operation = operationType
7481
};
7582
}
7683
}

src/Microsoft.OpenApi/Services/SearchResult.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System.Collections.Generic;
45
using Microsoft.OpenApi.Models;
56

67
namespace Microsoft.OpenApi.Services
@@ -19,5 +20,11 @@ public class SearchResult
1920
/// An Operation object.
2021
/// </summary>
2122
public OpenApiOperation Operation { get; set; }
23+
24+
/// <summary>
25+
/// Parameters object
26+
/// </summary>
27+
public IList<OpenApiParameter> Parameters { get; set; }
28+
2229
}
2330
}

0 commit comments

Comments
 (0)