Skip to content

Commit 5fdfa37

Browse files
authored
Merge pull request #135 from mattpolzin/v2/rename-templatedurl
prefer the name URLTemplate over TemplatedURL
2 parents a892264 + eb505f4 commit 5fdfa37

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

Sources/OpenAPIKit/Server.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension OpenAPI {
1313
/// See [OpenAPI Server Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#server-object).
1414
///
1515
public struct Server: Equatable, CodableVendorExtendable {
16-
public let urlTemplate: TemplatedURL
16+
public let urlTemplate: URLTemplate
1717
public let description: String?
1818
public let variables: OrderedDictionary<String, Variable>
1919

@@ -30,7 +30,7 @@ extension OpenAPI {
3030
variables: OrderedDictionary<String, Variable> = [:],
3131
vendorExtensions: [String: AnyCodable] = [:]
3232
) {
33-
self.urlTemplate = TemplatedURL(url: url)
33+
self.urlTemplate = URLTemplate(url: url)
3434
self.description = description
3535
self.variables = variables
3636
self.vendorExtensions = vendorExtensions
@@ -90,7 +90,7 @@ extension OpenAPI.Server: Decodable {
9090
public init(from decoder: Decoder) throws {
9191
let container = try decoder.container(keyedBy: CodingKeys.self)
9292

93-
urlTemplate = try container.decode(TemplatedURL.self, forKey: .url)
93+
urlTemplate = try container.decode(URLTemplate.self, forKey: .url)
9494
description = try container.decodeIfPresent(String.self, forKey: .description)
9595
variables = try container.decodeIfPresent(OrderedDictionary<String, Variable>.self, forKey: .variables) ?? [:]
9696

Sources/OpenAPIKit/TemplatedURL.swift Sources/OpenAPIKit/URLTemplate.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// TemplatedURL.swift
2+
// URLTemplate.swift
33
//
44
//
55
// Created by Mathew Polzin on 8/13/20.
@@ -31,7 +31,7 @@ import Foundation
3131
///
3232
/// // etc.
3333
///
34-
public struct TemplatedURL: Hashable, RawRepresentable {
34+
public struct URLTemplate: Hashable, RawRepresentable {
3535

3636
/// The string value of the URL.
3737
///
@@ -43,7 +43,7 @@ public struct TemplatedURL: Hashable, RawRepresentable {
4343
///
4444
/// This is equivalent to the `absoluteString` provided
4545
/// by the Foundation `URL` type except that a
46-
/// `TemplatedURL`'s `absoluteString` can contain
46+
/// `URLTemplate`'s `absoluteString` can contain
4747
/// variable placeholders.
4848
public var absoluteString: String {
4949
rawValue
@@ -57,7 +57,7 @@ public struct TemplatedURL: Hashable, RawRepresentable {
5757
return URL(string: rawValue)
5858
}
5959

60-
/// Create a TemplatedURL from the string if possible.
60+
/// Create a URLTemplate from the string if possible.
6161
public init?(rawValue: String) {
6262
// currently this is guaranteed to succeed but
6363
// in the future it will fail if variable placeholders
@@ -71,15 +71,15 @@ public struct TemplatedURL: Hashable, RawRepresentable {
7171
}
7272
}
7373

74-
extension TemplatedURL: Encodable {
74+
extension URLTemplate: Encodable {
7575
public func encode(to encoder: Encoder) throws {
7676
var container = encoder.singleValueContainer()
7777

7878
try container.encode(rawValue)
7979
}
8080
}
8181

82-
extension TemplatedURL: Decodable {
82+
extension URLTemplate: Decodable {
8383
public init(from decoder: Decoder) throws {
8484
let container = try decoder.singleValueContainer()
8585

@@ -91,4 +91,4 @@ extension TemplatedURL: Decodable {
9191
}
9292
}
9393

94-
extension TemplatedURL: Validatable {}
94+
extension URLTemplate: Validatable {}

Tests/OpenAPIKitTests/ServerTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ServerTests: XCTestCase {
3030
func test_serverInitialization() {
3131
let s1 = Server(url: URL(string: "https://hello.com")!)
3232

33-
XCTAssertEqual(s1.urlTemplate, TemplatedURL(rawValue: "https://hello.com")!)
33+
XCTAssertEqual(s1.urlTemplate, URLTemplate(rawValue: "https://hello.com")!)
3434
XCTAssertNil(s1.description)
3535
XCTAssertEqual(s1.variables, [:])
3636

@@ -41,7 +41,7 @@ class ServerTests: XCTestCase {
4141
"hello": variable
4242
])
4343

44-
XCTAssertEqual(s2.urlTemplate, TemplatedURL(rawValue: "https://hello.com")!)
44+
XCTAssertEqual(s2.urlTemplate, URLTemplate(rawValue: "https://hello.com")!)
4545
XCTAssertEqual(s2.description, "hello world")
4646
XCTAssertEqual(s2.variables, ["hello": variable])
4747
}

Tests/OpenAPIKitTests/TemplatedURLTests.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// TemplatedURLTests.swift
2+
// URLTemplateTests.swift
33
//
44
//
55
// Created by Mathew Polzin on 8/13/20.
@@ -9,24 +9,24 @@ import Foundation
99
import OpenAPIKit
1010
import XCTest
1111

12-
final class TemplatedURLTests: XCTestCase {
12+
final class URLTemplateTests: XCTestCase {
1313
func test_init() {
14-
XCTAssertNotNil(TemplatedURL(rawValue: "https://website.com"))
15-
XCTAssertEqual(TemplatedURL(rawValue: "https://website.com"), TemplatedURL(url: URL(string: "https://website.com")!))
14+
XCTAssertNotNil(URLTemplate(rawValue: "https://website.com"))
15+
XCTAssertEqual(URLTemplate(rawValue: "https://website.com"), URLTemplate(url: URL(string: "https://website.com")!))
1616
}
1717

1818
func test_urlAccess() {
19-
let t1 = TemplatedURL(rawValue: "https://website.com")
20-
let t2 = TemplatedURL(rawValue: "{scheme}://website.com")
19+
let t1 = URLTemplate(rawValue: "https://website.com")
20+
let t2 = URLTemplate(rawValue: "{scheme}://website.com")
2121

2222
XCTAssertEqual(t1?.url, URL(string: "https://website.com"))
2323
XCTAssertNil(t2?.url)
2424
}
2525

2626
func test_absoluteString() {
27-
let t1 = TemplatedURL(rawValue: "https://website.com")
28-
let t2 = TemplatedURL(rawValue: "/a/relative/path")
29-
let t3 = TemplatedURL(rawValue: "website.com?query=value")
27+
let t1 = URLTemplate(rawValue: "https://website.com")
28+
let t2 = URLTemplate(rawValue: "/a/relative/path")
29+
let t3 = URLTemplate(rawValue: "website.com?query=value")
3030

3131
XCTAssertEqual(t1?.absoluteString, URL(string: "https://website.com")?.absoluteString)
3232
XCTAssertEqual(t2?.absoluteString, URL(string: "/a/relative/path")?.absoluteString)
@@ -35,10 +35,10 @@ final class TemplatedURLTests: XCTestCase {
3535
}
3636

3737
// MARK: - Codable
38-
extension TemplatedURLTests {
38+
extension URLTemplateTests {
3939
func test_encode() throws {
4040
let t1 = TemplatedURLWrapper(
41-
url: TemplatedURL(rawValue: "https://website.com")
41+
url: URLTemplate(rawValue: "https://website.com")
4242
)
4343

4444
assertJSONEquivalent(
@@ -62,13 +62,13 @@ extension TemplatedURLTests {
6262

6363
XCTAssertEqual(
6464
t1.url,
65-
TemplatedURL(rawValue: "https://website.com")
65+
URLTemplate(rawValue: "https://website.com")
6666
)
6767
}
6868

6969
func test_encode_withVariables() throws {
7070
let t1 = TemplatedURLWrapper(
71-
url: TemplatedURL(rawValue: "{scheme}://{host}.com")
71+
url: URLTemplate(rawValue: "{scheme}://{host}.com")
7272
)
7373

7474
assertJSONEquivalent(
@@ -92,11 +92,11 @@ extension TemplatedURLTests {
9292

9393
XCTAssertEqual(
9494
t1.url,
95-
TemplatedURL(rawValue: "{scheme}://{host}.com")
95+
URLTemplate(rawValue: "{scheme}://{host}.com")
9696
)
9797
}
9898
}
9999

100100
fileprivate struct TemplatedURLWrapper: Codable {
101-
let url: TemplatedURL?
101+
let url: URLTemplate?
102102
}

Tests/OpenAPIKitTests/Validator/ValidatorTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ final class ValidatorTests: XCTestCase {
834834
.validating(
835835
"At least two servers are specified on root Document if one of them is the test server.",
836836
check: \.document.servers.count >= 2,
837-
when: \OpenAPI.Server.urlTemplate == TemplatedURL(rawValue: "https://test.server.com")!
837+
when: \OpenAPI.Server.urlTemplate == URLTemplate(rawValue: "https://test.server.com")!
838838
&& \.codingPath.first?.stringValue == "servers"
839839
)
840840

@@ -851,7 +851,7 @@ final class ValidatorTests: XCTestCase {
851851
.validating(
852852
"At least two servers are specified if one of them is the test server.",
853853
check: \.document.servers.count >= 2,
854-
when: \OpenAPI.Server.urlTemplate == TemplatedURL(rawValue: "https://test.server.com")!
854+
when: \OpenAPI.Server.urlTemplate == URLTemplate(rawValue: "https://test.server.com")!
855855
)
856856

857857
XCTAssertNoThrow(try document2.validate(using: validator2))

0 commit comments

Comments
 (0)