Skip to content

Commit 9863ba8

Browse files
Fixed issue with misaligned path components; fixed typo in parsing error; bump ClientSupport library (#12)
* Fix typo in error * Fix issue with path components being stripped * Bump ApodiniMigratorClientSupport to 0.2.0
1 parent b224604 commit 9863ba8

21 files changed

Lines changed: 80 additions & 40 deletions

Sources/ApodiniMigratorCore/WebService/Endpoint/EndpointPath.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,18 @@ public struct EndpointPath: Value, CustomStringConvertible, EndpointIdentifier {
4343

4444
/// String representation of the path
4545
public var description: String {
46-
Self.separator + components.sorted(by: \.key)
46+
Self.separator + components
47+
.sorted(by: \.key)
4748
.map { "\($0.value)" }
4849
.joined(separator: Self.separator)
4950
}
5051

5152
public var rawValue: String {
5253
description
5354
}
54-
55-
/// Path excluding the first component which corresponds to the version of the web service
55+
5656
public var resourcePath: String {
5757
components
58-
.filter { $0.key != 0 }
5958
.sorted(by: \.key)
6059
.map { "\($0.value)" }
6160
.joined(separator: Self.separator)

Sources/ApodiniMigratorCore/WebService/Legacy/LegacyServiceInformation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
struct LegacyServiceInformation: Codable {
1212
enum MigrationError: Error {
13-
case failedMath(path: String)
13+
case failedMatch(path: String)
1414
case failedHostnameExtraction(path: String)
1515
case failedPortConversion(path: String)
1616
}
@@ -28,10 +28,10 @@ extension HTTPInformation {
2828
public init(fromLegacyServerPath serverPath: String) throws {
2929
let range = NSRange(serverPath.startIndex..., in: serverPath)
3030
// swiftlint:disable:next force_try
31-
let regex = try! NSRegularExpression(pattern: "^http://(.+):([0-9]+)(/(\\w|\\d)+)?$")
31+
let regex = try! NSRegularExpression(pattern: "^http://(.+):([0-9]+)(/.*)?$")
3232

3333
guard let match = regex.firstMatch(in: serverPath, range: range) else {
34-
throw LegacyServiceInformation.MigrationError.failedMath(path: serverPath)
34+
throw LegacyServiceInformation.MigrationError.failedMatch(path: serverPath)
3535
}
3636

3737
guard let hostname = serverPath.retrieveMatch(match: match, at: 1),

Sources/RESTMigrator/RESTMigrator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ public struct RESTMigrator: ApodiniMigrator.Migrator {
132132
}
133133

134134
SwiftPackageFile(swiftTools: "5.5")
135-
.platform(".macOS(.v12)", ".iOS(.v14)")
136-
.dependency(url: "https://github.com/Apodini/ApodiniMigrator.git", ".upToNextMinor(from: \"0.1.0\")")
135+
.platform(".macOS(.v11)", ".iOS(.v13)")
136+
.dependency(url: "https://github.com/Apodini/ApodiniMigrator.git", ".upToNextMinor(from: \"0.2.0\")")
137137
.product(library: .packageName, targets: .packageName)
138138

139139
ReadMeFile("Readme.md")

Sources/RESTMigrator/Resources/Utils/Utils.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import PathKit
23
import ApodiniMigratorClientSupport
34

45
/// A typealias of `ApodiniMigratorDecodable`, a `Decodable` protocol
@@ -38,7 +39,7 @@ extension JSScript: Codable {}
3839
/// JSONValue conformance to `ApodiniMigratorCodable`
3940
extension JSONValue: Codable {}
4041

41-
/// Holds distincts resource cases with the name of the resource as raw value
42+
/// Holds distinct resource cases with the name of the resource as raw value
4243
private enum Resource: String {
4344
/// Javascript convert methods
4445
case jsScripts = "js-convert-scripts"
@@ -52,7 +53,7 @@ fileprivate extension Bundle {
5253
func resource<D: Decodable>(_ resource: Resource) -> D {
5354
guard
5455
let path = path(forResource: resource.rawValue, ofType: "json"),
55-
let instance = try? D.decode(from: path.asPath) else {
56+
let instance = try? D.decode(from: Path(path)) else {
5657
fatalError("Resource \(resource.rawValue) is malformed")
5758
}
5859
return instance

Tests/ApodiniMigratorTests/ApodiniMigratorCore/ApodiniMigratorModelsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ final class ApodiniMigratorModelsTests: ApodiniMigratorXCTestCase {
7676
let string2 = "/v2/{param}/users/{param}" // still considered equal, change is delegated to networking due to version change
7777

7878
XCTAssertNotEqual(EndpointPath(string), EndpointPath(string1))
79-
XCTAssertEqual(EndpointPath(string1), EndpointPath(string2))
79+
XCTAssertNotEqual(EndpointPath(string1), EndpointPath(string2))
8080
}
8181

8282
func testVersion() throws {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// This source file is part of the Apodini open source project
3+
//
4+
// SPDX-FileCopyrightText: 2019-2021 Paul Schmiedmayer and the Apodini project authors (see CONTRIBUTORS.md) <paul.schmiedmayer@tum.de>
5+
//
6+
// SPDX-License-Identifier: MIT
7+
//
8+
9+
import Foundation
10+
import XCTest
11+
@testable import ApodiniMigratorCore
12+
13+
final class LegacyHTTPInformation: XCTestCase {
14+
func testLegacyServerPath() throws {
15+
XCTAssertEqual(
16+
try HTTPInformation(fromLegacyServerPath: "http://localhost:8080"),
17+
HTTPInformation(hostname: "localhost", port: 8080)
18+
)
19+
20+
XCTAssertEqual(
21+
try HTTPInformation(fromLegacyServerPath: "http://localhost:8080/"),
22+
HTTPInformation(hostname: "localhost", port: 8080)
23+
)
24+
25+
XCTAssertEqual(
26+
try HTTPInformation(fromLegacyServerPath: "http://localhost:8080/asdf"),
27+
HTTPInformation(hostname: "localhost", port: 8080)
28+
)
29+
30+
XCTAssertEqual(
31+
try HTTPInformation(fromLegacyServerPath: "http://localhost:8080/asdf-asda_asdawd882"),
32+
HTTPInformation(hostname: "localhost", port: 8080)
33+
)
34+
35+
XCTAssertEqual(
36+
try HTTPInformation(fromLegacyServerPath: "http://127.0.0.1:8080"),
37+
HTTPInformation(hostname: "127.0.0.1", port: 8080)
38+
)
39+
}
40+
}

Tests/ApodiniMigratorTests/Resources/ExpectedOutputs/Auxiliary/APIFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public enum API {}
1010

1111
// MARK: - Endpoints
1212
public extension API {
13-
/// API call for TestHandler at: hello
13+
/// API call for TestHandler at: v1/hello
1414
static func sayHelloWorld(
1515
authorization: String? = nil,
1616
httpHeaders: HTTPHeaders = [:]

Tests/ApodiniMigratorTests/Resources/ExpectedOutputs/Endpoint/DefaultEndpointFile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77

88
// MARK: - Endpoints
99
public extension TestResponse {
10-
/// API call for TestHandler at: tests/{second}
10+
/// API call for TestHandler at: v1/tests/{second}
1111
static func testEndpoint(
1212
first: String,
1313
isDriving: String?,
@@ -27,7 +27,7 @@ public extension TestResponse {
2727
errors.addError(404, message: "Not found")
2828

2929
let handler = Handler<TestResponse>(
30-
path: "tests/\(second)",
30+
path: "v1/tests/\(second)",
3131
httpMethod: .get,
3232
parameters: parameters,
3333
headers: headers,

Tests/ApodiniMigratorTests/Resources/ExpectedOutputs/Endpoint/EndpointAddParameterChange.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77

88
// MARK: - Endpoints
99
public extension TestResponse {
10-
/// API call for TestHandler at: tests/{second}
10+
/// API call for TestHandler at: v1/tests/{second}
1111
static func testEndpoint(
1212
first: String,
1313
isDriving: String?,
@@ -29,7 +29,7 @@ public extension TestResponse {
2929
errors.addError(404, message: "Not found")
3030

3131
let handler = Handler<TestResponse>(
32-
path: "tests/\(second)",
32+
path: "v1/tests/\(second)",
3333
httpMethod: .get,
3434
parameters: parameters,
3535
headers: headers,

Tests/ApodiniMigratorTests/Resources/ExpectedOutputs/Endpoint/EndpointDeleteContentParameterChange.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77

88
// MARK: - Endpoints
99
public extension TestResponse {
10-
/// API call for TestHandler at: tests/{second}
10+
/// API call for TestHandler at: v1/tests/{second}
1111
static func testEndpoint(
1212
first: String,
1313
isDriving: String?,
@@ -27,7 +27,7 @@ public extension TestResponse {
2727
errors.addError(404, message: "Not found")
2828

2929
let handler = Handler<TestResponse>(
30-
path: "tests/\(second)",
30+
path: "v1/tests/\(second)",
3131
httpMethod: .get,
3232
parameters: parameters,
3333
headers: headers,

0 commit comments

Comments
 (0)