Skip to content

Commit

Permalink
Support UUID as a StringVariableValue
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdeem committed Jun 9, 2024
1 parent ad49467 commit 42b5790
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/ScreamURITemplate/VariableValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ extension UInt32: StringVariableValue {}
extension UInt64: StringVariableValue {}
extension UInt8: StringVariableValue {}
extension Unicode.Scalar: StringVariableValue {}

extension UUID: StringVariableValue {
public func asStringVariableValue() -> String {
uuidString
}
}
9 changes: 9 additions & 0 deletions Tests/ScreamURITemplateTests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ class Tests: XCTestCase {
].contains(urlString))
}

func testUUIDVariable() throws {
let template: URITemplate = "https://api.example.com/{id}"
let variables: VariableDictionary = [
"id": UUID(uuidString: "1740A1A9-B3AD-4AE9-954B-918CEDE95285")!,
]
let urlString = try template.process(variables: variables)
XCTAssertEqual(urlString, "https://api.example.com/1740A1A9-B3AD-4AE9-954B-918CEDE95285")
}

func testSendable() {
let template: URITemplate = "https://api.github.com/repos/{owner}/{repo}/collaborators/{username}"
let sendable = template as Sendable
Expand Down

0 comments on commit 42b5790

Please sign in to comment.