File tree 2 files changed +15
-2
lines changed
Sources/OpenAPIKit/Path Item
Tests/OpenAPIKitTests/Path Item
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -12,20 +12,28 @@ extension OpenAPI {
12
12
/// and [OpenAPI Patterned Fields](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#patterned-fields).
13
13
public struct Path : RawRepresentable , Equatable , Hashable {
14
14
public let components : [ String ]
15
+ public let trailingSlash : Bool
15
16
16
- public init ( _ components: [ String ] ) {
17
+ public init ( _ components: [ String ] , trailingSlash : Bool = false ) {
17
18
self . components = components
19
+ self . trailingSlash = trailingSlash
18
20
}
19
21
20
22
public init ( rawValue: String ) {
21
23
let pathComponents = rawValue. split ( separator: " / " ) . map ( String . init)
22
24
components = pathComponents. count > 0 && pathComponents [ 0 ] . isEmpty
23
25
? Array ( pathComponents. dropFirst ( ) )
24
26
: pathComponents
27
+ trailingSlash = rawValue. hasSuffix ( " / " )
25
28
}
26
29
27
30
public var rawValue : String {
28
- return " / \( components. joined ( separator: " / " ) ) "
31
+ let path =
32
+ " / \( components. joined ( separator: " / " ) ) "
33
+
34
+ let suffix = trailingSlash ? " / " : " "
35
+
36
+ return path + suffix
29
37
}
30
38
}
31
39
}
Original file line number Diff line number Diff line change @@ -15,17 +15,22 @@ final class PathItemTests: XCTestCase {
15
15
let t3 = OpenAPI . Path ( rawValue: " hello/world " )
16
16
let t4 : OpenAPI . Path = " /hello/world "
17
17
let t5 : OpenAPI . Path = " hello/world "
18
+ let t6 : OpenAPI . Path = " hello/world/ "
19
+ let t7 = OpenAPI . Path ( [ " hello " , " world " ] , trailingSlash: true )
18
20
19
21
XCTAssertEqual ( t1, t2)
20
22
XCTAssertEqual ( t2, t3)
21
23
XCTAssertEqual ( t3, t4)
22
24
XCTAssertEqual ( t4, t5)
25
+ XCTAssertNotEqual ( t5, t6)
26
+ XCTAssertEqual ( t6, t7)
23
27
24
28
XCTAssertEqual ( t1. rawValue, " /hello/world " )
25
29
XCTAssertEqual ( t2. rawValue, " /hello/world " )
26
30
XCTAssertEqual ( t3. rawValue, " /hello/world " )
27
31
XCTAssertEqual ( t4. rawValue, " /hello/world " )
28
32
XCTAssertEqual ( t5. rawValue, " /hello/world " )
33
+ XCTAssertEqual ( t6. rawValue, " /hello/world/ " )
29
34
}
30
35
31
36
func test_initializePathItem( ) {
You can’t perform that action at this time.
0 commit comments