Skip to content

Commit a08f1dc

Browse files
committed
Add convenience accessor on PathItem.Properties that allows easier abstractions on the HTTP verb for which operations are being requested.
1 parent 0cf86fe commit a08f1dc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Sources/OpenAPIKit/Path Item/PathItem.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
import Foundation
99
import Poly
1010

11+
extension OpenAPI {
12+
public enum HttpVerb: String {
13+
case get = "GET"
14+
case post = "POST"
15+
case patch = "PATCH"
16+
case put = "PUT"
17+
case delete = "DELETE"
18+
case head = "HEAD"
19+
case options = "OPTIONS"
20+
}
21+
}
22+
1123
extension OpenAPI {
1224
public struct PathComponents: RawRepresentable, Equatable, Hashable {
1325
public let components: [String]
@@ -84,6 +96,27 @@ extension OpenAPI.PathItem {
8496
}
8597
}
8698

99+
extension OpenAPI.PathItem.Properties {
100+
public func `for`(_ verb: OpenAPI.HttpVerb) -> Operation? {
101+
switch verb {
102+
case .delete:
103+
return self.delete
104+
case .get:
105+
return self.get
106+
case .head:
107+
return self.head
108+
case .options:
109+
return self.options
110+
case .patch:
111+
return self.patch
112+
case .post:
113+
return self.post
114+
case .put:
115+
return self.put
116+
}
117+
}
118+
}
119+
87120
// MARK: - Codable
88121

89122
extension OpenAPI.PathComponents: Encodable {

0 commit comments

Comments
 (0)