Skip to content

Commit c5aa61b

Browse files
authored
Merge branch 'main' into release/4_0
2 parents 8353ec0 + 90c137c commit c5aa61b

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

Sources/OpenAPIKit/Document/Document.swift

+11-10
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,13 @@ extension OpenAPI.Document {
217217
}
218218
}
219219

220-
/// Retrieve an array of all locally defined Operation Ids defined by
221-
/// this API. These Ids are guaranteed to be unique by
220+
/// Retrieve an array of all Operation Ids defined by locally
221+
/// by this API. These Ids are guaranteed to be unique by
222222
/// the OpenAPI Specification.
223223
///
224-
/// PathItems will be looked up in the components, but any remote references
225-
/// or path items missing from the components will be ignored.
224+
/// `PathItems` from `paths` and `webhooks` will be looked
225+
/// up in the components, but any remote references or path items
226+
/// missing from the components will be ignored.
226227
///
227228
/// The ordering is not necessarily significant, but it will
228229
/// be the order in which each operation is occurred within
@@ -232,10 +233,10 @@ extension OpenAPI.Document {
232233
/// See [Operation Object](https://spec.openapis.org/oas/v3.1.1.html#operation-object) in the specifcation.
233234
///
234235
public var allOperationIds: [String] {
235-
return paths.values
236-
.compactMap { components[$0] }
237-
.flatMap { $0.endpoints }
238-
.compactMap { $0.operation.operationId }
236+
return (paths.values + webhooks.values)
237+
.compactMap { components[$0] }
238+
.flatMap { $0.endpoints }
239+
.compactMap { $0.operation.operationId }
239240
}
240241

241242
/// All servers referenced anywhere in the whole document.
@@ -296,7 +297,7 @@ extension OpenAPI.Document {
296297
}
297298
}
298299

299-
for pathItem in paths.values {
300+
for pathItem in (paths.values + webhooks.values) {
300301
let pathItemServers = components[pathItem]?.servers ?? []
301302
pathItemServers.forEach(insertUniquely)
302303

@@ -317,7 +318,7 @@ extension OpenAPI.Document {
317318
public var allTags: Set<String> {
318319
return Set(
319320
(tags ?? []).map { $0.name }
320-
+ paths.values.compactMap { components[$0] }
321+
+ (paths.values + webhooks.values).compactMap { components[$0] }
321322
.flatMap { $0.endpoints }
322323
.flatMap { $0.operation.tags ?? [] }
323324
)

Tests/OpenAPIKitTests/Document/DocumentTests.swift

+34
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ final class DocumentTests: XCTestCase {
7979
}
8080

8181
func test_getAllOperationIds() {
82+
// paths, no operation ids, no components, no webhooks
8283
let t1 = OpenAPI.Document(
8384
info: .init(title: "test", version: "1.0"),
8485
servers: [],
@@ -93,6 +94,7 @@ final class DocumentTests: XCTestCase {
9394

9495
XCTAssertEqual(t1.allOperationIds, [])
9596

97+
// paths, one operation id (second one nil), no components, no webhooks
9698
let t2 = OpenAPI.Document(
9799
info: .init(title: "test", version: "1.0"),
98100
servers: [],
@@ -107,6 +109,7 @@ final class DocumentTests: XCTestCase {
107109

108110
XCTAssertEqual(t2.allOperationIds, ["test"])
109111

112+
// paths, multiple operation ids, no components, no webhooks
110113
let t3 = OpenAPI.Document(
111114
info: .init(title: "test", version: "1.0"),
112115
servers: [],
@@ -121,6 +124,7 @@ final class DocumentTests: XCTestCase {
121124

122125
XCTAssertEqual(t3.allOperationIds, ["test", "two"])
123126

127+
// paths, one operation id (first one nil), no components, no webhooks
124128
let t4 = OpenAPI.Document(
125129
info: .init(title: "test", version: "1.0"),
126130
servers: [],
@@ -134,6 +138,36 @@ final class DocumentTests: XCTestCase {
134138
)
135139

136140
XCTAssertEqual(t4.allOperationIds, ["two"])
141+
142+
// paths, one operation id, one component reference, no webhooks
143+
let t5 = OpenAPI.Document(
144+
info: .init(title: "test", version: "1.0"),
145+
servers: [],
146+
paths: [
147+
"/hello": .init(
148+
get: .init(operationId: "test", responses: [:])),
149+
"/hello/world": .reference(.component(named: "hello-world"))
150+
],
151+
components: .init(
152+
pathItems: ["hello-world": .init(put: .init(operationId: "two", responses: [:]))]
153+
)
154+
)
155+
156+
XCTAssertEqual(t5.allOperationIds, ["test", "two"])
157+
158+
// no paths, one webhook with an operation id
159+
let t6 = OpenAPI.Document(
160+
info: .init(title: "test", version: "1.0"),
161+
servers: [],
162+
paths: [:],
163+
webhooks: [
164+
"/hello": .init(
165+
get: .init(operationId: "test", responses: [:]))
166+
],
167+
components: .noComponents
168+
)
169+
170+
XCTAssertEqual(t6.allOperationIds, ["test"])
137171
}
138172

139173
func test_allServersEmpty() {

0 commit comments

Comments
 (0)