Skip to content

Commit 7b4dd6b

Browse files
authored
Include path item parameters in filter (#658)
### Motivation When filtering by a specific operationId, any path item-level parameters were not included (only operation-level parameters). ### Modifications Include path item level parameters. ### Result No errors for missing references when filtering for operations that have a path item-level parameter with a reference. ### Test Plan Adapted unit tests to cover this.
1 parent 924cf2f commit 7b4dd6b

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

Sources/_OpenAPIGeneratorCore/Hooks/FilteredDocument.swift

+1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ private extension FilteredDocumentBuilder {
313313
guard predicate(endpoint) else { continue }
314314
if requiredEndpoints[path] == nil { requiredEndpoints[path] = Set() }
315315
if requiredEndpoints[path]!.insert(endpoint.method).inserted {
316+
for parameter in originalPathItem.parameters { try includeParameter(parameter) }
316317
try includeComponentsReferencedBy(endpoint.operation)
317318
}
318319
}

Tests/OpenAPIGeneratorCoreTests/Hooks/Test_FilteredDocument.swift

+43-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ final class Test_FilteredDocument: XCTestCase {
2828
- name: t
2929
paths:
3030
/things/a:
31+
parameters:
32+
- $ref: '#/components/parameters/A'
3133
get:
3234
operationId: getA
3335
tags:
@@ -52,6 +54,12 @@ final class Test_FilteredDocument: XCTestCase {
5254
type: string
5355
B:
5456
$ref: '#/components/schemas/A'
57+
parameters:
58+
A:
59+
in: query
60+
schema:
61+
type: string
62+
name: A
5563
responses:
5664
A:
5765
description: success
@@ -75,14 +83,16 @@ final class Test_FilteredDocument: XCTestCase {
7583
filter: DocumentFilter(tags: ["t"]),
7684
hasPaths: ["/things/a"],
7785
hasOperations: ["getA"],
78-
hasSchemas: ["A"]
86+
hasSchemas: ["A"],
87+
hasParameters: ["A"]
7988
)
8089
assert(
8190
filtering: document,
8291
filter: DocumentFilter(paths: ["/things/a"]),
8392
hasPaths: ["/things/a"],
8493
hasOperations: ["getA", "deleteA"],
85-
hasSchemas: ["A"]
94+
hasSchemas: ["A"],
95+
hasParameters: ["A"]
8696
)
8797
assert(
8898
filtering: document,
@@ -96,7 +106,8 @@ final class Test_FilteredDocument: XCTestCase {
96106
filter: DocumentFilter(paths: ["/things/a", "/things/b"]),
97107
hasPaths: ["/things/a", "/things/b"],
98108
hasOperations: ["getA", "deleteA", "getB"],
99-
hasSchemas: ["A", "B"]
109+
hasSchemas: ["A", "B"],
110+
hasParameters: ["A"]
100111
)
101112
assert(
102113
filtering: document,
@@ -117,21 +128,24 @@ final class Test_FilteredDocument: XCTestCase {
117128
filter: DocumentFilter(paths: ["/things/a"], schemas: ["B"]),
118129
hasPaths: ["/things/a"],
119130
hasOperations: ["getA", "deleteA"],
120-
hasSchemas: ["A", "B"]
131+
hasSchemas: ["A", "B"],
132+
hasParameters: ["A"]
121133
)
122134
assert(
123135
filtering: document,
124136
filter: DocumentFilter(tags: ["t"], schemas: ["B"]),
125137
hasPaths: ["/things/a"],
126138
hasOperations: ["getA"],
127-
hasSchemas: ["A", "B"]
139+
hasSchemas: ["A", "B"],
140+
hasParameters: ["A"]
128141
)
129142
assert(
130143
filtering: document,
131144
filter: DocumentFilter(operations: ["deleteA"]),
132145
hasPaths: ["/things/a"],
133146
hasOperations: ["deleteA"],
134-
hasSchemas: []
147+
hasSchemas: [],
148+
hasParameters: ["A"]
135149
)
136150
}
137151

@@ -141,6 +155,7 @@ final class Test_FilteredDocument: XCTestCase {
141155
hasPaths paths: [OpenAPI.Path.RawValue],
142156
hasOperations operationIDs: [String],
143157
hasSchemas schemas: [String],
158+
hasParameters parameters: [String] = [],
144159
file: StaticString = #filePath,
145160
line: UInt = #line
146161
) {
@@ -149,11 +164,31 @@ final class Test_FilteredDocument: XCTestCase {
149164
XCTFail("Filter threw error: \(error)", file: file, line: line)
150165
return
151166
}
152-
XCTAssertUnsortedEqual(filteredDocument.paths.keys.map(\.rawValue), paths, file: file, line: line)
153-
XCTAssertUnsortedEqual(filteredDocument.allOperationIds, operationIDs, file: file, line: line)
167+
XCTAssertUnsortedEqual(
168+
filteredDocument.paths.keys.map(\.rawValue),
169+
paths,
170+
"Paths don't match",
171+
file: file,
172+
line: line
173+
)
174+
XCTAssertUnsortedEqual(
175+
filteredDocument.allOperationIds,
176+
operationIDs,
177+
"Operations don't match",
178+
file: file,
179+
line: line
180+
)
154181
XCTAssertUnsortedEqual(
155182
filteredDocument.components.schemas.keys.map(\.rawValue),
156183
schemas,
184+
"Schemas don't match",
185+
file: file,
186+
line: line
187+
)
188+
XCTAssertUnsortedEqual(
189+
filteredDocument.components.parameters.keys.map(\.rawValue),
190+
parameters,
191+
"Parameters don't match",
157192
file: file,
158193
line: line
159194
)

0 commit comments

Comments
 (0)