forked from wei18/github-rest-api-swift-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorConfigBuilder.swift
More file actions
67 lines (54 loc) · 1.52 KB
/
GeneratorConfigBuilder.swift
File metadata and controls
67 lines (54 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// GeneratorConfigBuilder.swift
// GitHubRestAPISwiftOpenAPI
//
// Created by zwc on 2024/1/6.
//
import Foundation
struct ErrorMessage: LocalizedError {
var message: String
var errorDescription: String? { message }
init(message: String, line: Int = #line) {
self.message = "\(line): \(message)"
}
}
struct GeneratorConfigBuilder {
let tagString: String
func getTemplate() -> String {
return #"""
generate:
- types
- client
filter:
tags:
- \#(tagString)
accessModifier: public
namingStrategy: idiomatic
nameOverrides:
'reactions-+1': reactionsThumbsUp
'reactions--1': reactionsThumbsDown
"""#
}
init(tag: String) {
self.tagString = tag
}
func write() throws {
let fileURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
.appendingPathComponent("Sources")
.appendingPathComponent(tagString)
.appendingPathComponent("openapi-generator-config.yml")
let fileContent = getTemplate()
guard let data = fileContent.data(using: .utf8) else {
throw ErrorMessage(message: "Variable data not found.")
}
try data.write(to: fileURL)
}
}
if let argTag = CommandLine.arguments[1]
.split(whereSeparator: \.isNewline)
.first {
let tag = String(argTag)
try GeneratorConfigBuilder(tag: tag).write()
} else {
throw ErrorMessage(message: "No tag not found.")
}