Skip to content

Commit 41bdd5f

Browse files
committed
Fix archive func for directories that do not exist ahead of time. change default location of zipped test files.
1 parent e68c51c commit 41bdd5f

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ ENV ENVIRONMENT=$env
6060
# Optional. If not specified, defaults to ~/api_test
6161
# ENV API_TEST_OUT_PATH
6262

63+
# Path on local filesystem to which to write zipped generated API test files.
64+
# Optional. If not specified, defaults to ~/api_test_archives
65+
# ENV API_TEST_ARCHIVES_PATH
66+
6367
# Postgres Database URL. Required.
6468
# ENV API_TEST_DATABASE_URL
6569

Sources/App/Environment/APITestEnvironment+server.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public extension Environment {
3131
public extension Environment {
3232
/// Optional Archives path (folder location in which zip archives will be stored).
3333
static var archivesPath: String {
34-
return Environment.get("API_TEST_ARCHIVES_PATH") ?? "/app/archives/"
34+
let defaultDir = FileManager.default
35+
.homeDirectoryForCurrentUser
36+
.appendingPathComponent("api_test_archives")
37+
.path
38+
39+
return Environment.get("API_TEST_ARCHIVES_PATH") ?? defaultDir
3540
}
3641
}

Sources/AppAPIDocumentation/VaporRoute+OpenAPI.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ extension AbstractRouteContext {
3838

3939
let schema = try (responseTuple.responseBodyType as? OpenAPIEncodedNodeType.Type)?.openAPINode(using: encoder)
4040

41+
// TODO: support additional content types -- binary file types will not even have a schema so they are gimmes.
42+
4143
return schema
4244
.map {
4345
OpenAPI.Response(

Sources/SwiftGen/ApiTestPackageSwiftGen.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,27 @@ func write(contents: String, toFileAt path: String, named name: String) throws {
384384
encoding: .utf8)
385385
}
386386

387-
func archive(from sourcePath: String, to archivePath: String) throws {
387+
func archive(from sourcePath: String, to archiveFilePath: String) throws {
388388
let fileManager = FileManager.default
389389

390-
if fileManager.fileExists(atPath: archivePath) {
391-
try fileManager.removeItem(atPath: archivePath)
390+
let source = URL(fileURLWithPath: sourcePath)
391+
let destination = URL(fileURLWithPath: archiveFilePath)
392+
393+
let archiveFolderPath = destination
394+
.deletingLastPathComponent()
395+
.path
396+
397+
// create the directory if needed
398+
if !fileManager.fileExists(atPath: archiveFolderPath) {
399+
try fileManager.createDirectory(atPath: archiveFolderPath,
400+
withIntermediateDirectories: true,
401+
attributes: nil)
392402
}
393403

394-
let source = URL(fileURLWithPath: sourcePath)
395-
let destination = URL(fileURLWithPath: archivePath)
404+
// delete a previously generated archive if needed
405+
if fileManager.fileExists(atPath: archiveFilePath) {
406+
try fileManager.removeItem(atPath: archiveFilePath)
407+
}
396408

397409
try fileManager.zipItem(at: source, to: destination)
398410
}

0 commit comments

Comments
 (0)