Skip to content

Commit 8e9b051

Browse files
Refactor Apodini Document Export (#13)
* Add ApodiniDocumentExport dependency to refactor ApodiniMigratorShared * Update ApodiniDocumentExport dependency * Move JSONDecoder Equatable conformance extensions to ApodiniMigratorSharedTests * Remove redundant OutputFormat ExpressibleByArgument extension * Update APIDocument test in ApodiniMigratorCore to restore test coverage
1 parent 9863ba8 commit 8e9b051

19 files changed

Lines changed: 123 additions & 217 deletions

Package.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ let package = Package(
3636
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMajor(from: "1.0.0")),
3737

3838
// testing runtime crashes
39-
.package(url: "https://github.com/norio-nomura/XCTAssertCrash.git", from: "0.2.0")
39+
.package(url: "https://github.com/norio-nomura/XCTAssertCrash.git", from: "0.2.0"),
40+
41+
.package(url: "https://github.com/Apodini/ApodiniDocumentExport.git", .upToNextMinor(from: "0.1.0"))
4042
],
4143
targets: [
4244
// The lowest level ApodiniMigrator package providing common API used across several targets, including
@@ -46,7 +48,8 @@ let package = Package(
4648
dependencies: [
4749
.product(name: "PathKit", package: "PathKit"),
4850
.product(name: "FineJSON", package: "FineJSON"),
49-
.product(name: "Yams", package: "Yams")
51+
.product(name: "Yams", package: "Yams"),
52+
.product(name: "ApodiniDocumentExport", package: "ApodiniDocumentExport")
5053
]
5154
),
5255

@@ -97,7 +100,8 @@ let package = Package(
97100
.target(name: "ApodiniMigrator"),
98101
.target(name: "ApodiniMigratorCompare"),
99102
.target(name: "ApodiniMigratorClientSupport"),
100-
.product(name: "Logging", package: "swift-log")
103+
.product(name: "Logging", package: "swift-log"),
104+
.product(name: "ApodiniDocumentExport", package: "ApodiniDocumentExport")
101105
],
102106
resources: [
103107
.process("Resources")
@@ -112,7 +116,8 @@ let package = Package(
112116
dependencies: [
113117
.target(name: "RESTMigrator"),
114118
.product(name: "ArgumentParser", package: "swift-argument-parser"),
115-
.product(name: "Logging", package: "swift-log")
119+
.product(name: "Logging", package: "swift-log"),
120+
.product(name: "ApodiniDocumentExport", package: "ApodiniDocumentExport")
116121
]
117122
),
118123

@@ -124,7 +129,8 @@ let package = Package(
124129
"RESTMigrator",
125130
"ApodiniMigratorCompare",
126131
"ApodiniMigratorClientSupport",
127-
.product(name: "XCTAssertCrash", package: "XCTAssertCrash", condition: .when(platforms: [.macOS]))
132+
.product(name: "XCTAssertCrash", package: "XCTAssertCrash", condition: .when(platforms: [.macOS])),
133+
.product(name: "ApodiniDocumentExport", package: "ApodiniDocumentExport")
128134
],
129135
resources: [
130136
.process("Resources")

Sources/ApodiniMigratorCLI/Compare.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Foundation
1010
import ArgumentParser
1111
import RESTMigrator
12+
import ApodiniDocumentExport
1213

1314
struct Compare: ParsableCommand {
1415
static var configuration = CommandConfiguration(
@@ -41,6 +42,3 @@ struct Compare: ParsableCommand {
4142
}
4243
}
4344
}
44-
45-
// MARK: - OutputFormat + ExpressibleByArgument
46-
extension OutputFormat: ExpressibleByArgument {}

Sources/ApodiniMigratorShared/Extensions/Decodable+Extension.swift

Lines changed: 0 additions & 49 deletions
This file was deleted.

Sources/ApodiniMigratorShared/Extensions/Encodable+Extensions.swift

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
// MARK: - KeyedDecodingContainerProtocol
10+
extension KeyedDecodingContainerProtocol {
11+
/// Decodes a value of the given collection type for the given key, if present, otherwise initalizes it as empty collection
12+
public func decodeIfPresentOrInitEmpty<T: Decodable>(_ type: T.Type, forKey key: Key) throws -> T where T: Collection, T.Element: Decodable {
13+
// swiftlint:disable:next force_cast
14+
(try decodeIfPresent(T.self, forKey: key)) ?? [] as! T
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
// MARK: - KeyedEncodingContainerProtocol
10+
extension KeyedEncodingContainerProtocol {
11+
/// Only encodes the value if the collection is not empty
12+
public mutating func encodeIfNotEmpty<T: Encodable>(_ value: T, forKey key: Key) throws where T: Collection, T.Element: Encodable {
13+
if !value.isEmpty {
14+
try encode(value, forKey: key)
15+
}
16+
}
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 PathKit
11+
import ApodiniDocumentExport
12+
13+
public extension Path {
14+
15+
/// Returns all swift files in `self` and in subdirectories of `self`
16+
func recursiveSwiftFiles() throws -> [Path] {
17+
guard isDirectory else {
18+
return []
19+
}
20+
return try recursiveChildren().filter { $0.is(.swift) }
21+
}
22+
}

Sources/ApodiniMigratorShared/Extensions/String+Extensions.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
import Foundation
10-
import PathKit
1110

1211
public extension String {
1312
/// Line break
@@ -48,9 +47,4 @@ public extension String {
4847
}
4948
return self
5049
}
51-
52-
/// Returns encoded data of `self`
53-
func data(_ encoding: Encoding = .utf8) -> Data {
54-
data(using: encoding) ?? .init()
55-
}
5650
}

Sources/ApodiniMigratorShared/FileExtension.swift

Lines changed: 0 additions & 54 deletions
This file was deleted.

Sources/ApodiniMigratorShared/OutputFormat.swift

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)