Skip to content

Commit 9f673f7

Browse files
author
Sven
committed
refact: 文件目录调整,准备添加测试用例
1 parent 9febece commit 9f673f7

File tree

10 files changed

+151
-37
lines changed

10 files changed

+151
-37
lines changed

SwiftJSONModeler For Xcode.xcodeproj/project.pbxproj

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
C92A970A24E512BD00C87CCD /* YApiObjectTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92A970524E50D5900C87CCD /* YApiObjectTest.swift */; };
11+
C92A971424E513EA00C87CCD /* YApiHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94AFC00241F4AE600389AF3 /* YApiHelper.swift */; };
12+
C92A971524E513EA00C87CCD /* YApiObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94AFC03241F4E8A00389AF3 /* YApiObject.swift */; };
13+
C92A971624E513EA00C87CCD /* YApiCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CEE26C242B382900A04EA9 /* YApiCreator.swift */; };
14+
C92A971724E513EA00C87CCD /* YApiRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D04F20242EF99F00843DC4 /* YApiRequest.swift */; };
15+
C92A971824E513F900C87CCD /* ErrorCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CB247F241F559C00F4D5CE /* ErrorCenter.swift */; };
16+
C92A971D24E514FB00C87CCD /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92A971C24E514FB00C87CCD /* Constants.swift */; };
17+
C92A971E24E5150600C87CCD /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92A971C24E514FB00C87CCD /* Constants.swift */; };
1018
C94AFC01241F4AE600389AF3 /* YApiHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94AFC00241F4AE600389AF3 /* YApiHelper.swift */; };
1119
C94AFC04241F4E8A00389AF3 /* YApiObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94AFC03241F4E8A00389AF3 /* YApiObject.swift */; };
1220
C961C1DE23D82A8D008D0DE6 /* ConfigViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C961C1DD23D82A8D008D0DE6 /* ConfigViewController.swift */; };
@@ -58,6 +66,8 @@
5866
/* End PBXCopyFilesBuildPhase section */
5967

6068
/* Begin PBXFileReference section */
69+
C92A970524E50D5900C87CCD /* YApiObjectTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YApiObjectTest.swift; sourceTree = "<group>"; };
70+
C92A971C24E514FB00C87CCD /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
6171
C94AFC00241F4AE600389AF3 /* YApiHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YApiHelper.swift; sourceTree = "<group>"; };
6272
C94AFC03241F4E8A00389AF3 /* YApiObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YApiObject.swift; sourceTree = "<group>"; };
6373
C961C1DD23D82A8D008D0DE6 /* ConfigViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigViewController.swift; sourceTree = "<group>"; };
@@ -109,6 +119,14 @@
109119
/* End PBXFrameworksBuildPhase section */
110120

111121
/* Begin PBXGroup section */
122+
C92A971B24E514D700C87CCD /* Constants */ = {
123+
isa = PBXGroup;
124+
children = (
125+
C92A971C24E514FB00C87CCD /* Constants.swift */,
126+
);
127+
path = Constants;
128+
sourceTree = "<group>";
129+
};
112130
C94AFC02241F4E6D00389AF3 /* YApi */ = {
113131
isa = PBXGroup;
114132
children = (
@@ -133,6 +151,7 @@
133151
C9D04F32242F228400843DC4 /* SwiftJSONModelerTest */ = {
134152
isa = PBXGroup;
135153
children = (
154+
C92A970524E50D5900C87CCD /* YApiObjectTest.swift */,
136155
);
137156
path = SwiftJSONModelerTest;
138157
sourceTree = "<group>";
@@ -161,6 +180,8 @@
161180
C9ED9CC423D7F9B3004567A1 /* SwiftJSONModeler For Xcode */ = {
162181
isa = PBXGroup;
163182
children = (
183+
C92A971B24E514D700C87CCD /* Constants */,
184+
C94AFC02241F4E6D00389AF3 /* YApi */,
164185
C9ED9CC523D7F9B3004567A1 /* AppDelegate.swift */,
165186
C9ED9CC923D7F9B3004567A1 /* Document.swift */,
166187
C9ED9CCB23D7F9B4004567A1 /* Assets.xcassets */,
@@ -169,6 +190,7 @@
169190
C9ED9CD123D7F9B4004567A1 /* SwiftJSONModeler For Xcode.entitlements */,
170191
C961C1DD23D82A8D008D0DE6 /* ConfigViewController.swift */,
171192
C9DE045E242C8535008A0070 /* Config.swift */,
193+
C9CB247F241F559C00F4D5CE /* ErrorCenter.swift */,
172194
);
173195
path = "SwiftJSONModeler For Xcode";
174196
sourceTree = "<group>";
@@ -184,10 +206,8 @@
184206
C9ED9CDF23D7F9D0004567A1 /* SwiftJSONModeler */ = {
185207
isa = PBXGroup;
186208
children = (
187-
C94AFC02241F4E6D00389AF3 /* YApi */,
188209
C9ED9CE023D7F9D0004567A1 /* SourceEditorExtension.swift */,
189210
C9ED9CE223D7F9D0004567A1 /* SourceEditorCommand.swift */,
190-
C9CB247F241F559C00F4D5CE /* ErrorCenter.swift */,
191211
C9ED9CE423D7F9D0004567A1 /* Info.plist */,
192212
C9ED9CE523D7F9D0004567A1 /* SwiftJSONModeler.entitlements */,
193213
);
@@ -325,17 +345,24 @@
325345
buildActionMask = 2147483647;
326346
files = (
327347
C9D04F2B242F218200843DC4 /* SwiftJSONModeler_For_XcodeTests.swift in Sources */,
348+
C92A970A24E512BD00C87CCD /* YApiObjectTest.swift in Sources */,
328349
);
329350
runOnlyForDeploymentPostprocessing = 0;
330351
};
331352
C9ED9CBE23D7F9B3004567A1 /* Sources */ = {
332353
isa = PBXSourcesBuildPhase;
333354
buildActionMask = 2147483647;
334355
files = (
356+
C92A971724E513EA00C87CCD /* YApiRequest.swift in Sources */,
357+
C92A971824E513F900C87CCD /* ErrorCenter.swift in Sources */,
335358
C9ED9CC623D7F9B3004567A1 /* AppDelegate.swift in Sources */,
359+
C92A971624E513EA00C87CCD /* YApiCreator.swift in Sources */,
336360
C9DE045F242C8535008A0070 /* Config.swift in Sources */,
361+
C92A971D24E514FB00C87CCD /* Constants.swift in Sources */,
362+
C92A971424E513EA00C87CCD /* YApiHelper.swift in Sources */,
337363
C9ED9CCA23D7F9B3004567A1 /* Document.swift in Sources */,
338364
C961C1DE23D82A8D008D0DE6 /* ConfigViewController.swift in Sources */,
365+
C92A971524E513EA00C87CCD /* YApiObject.swift in Sources */,
339366
);
340367
runOnlyForDeploymentPostprocessing = 0;
341368
};
@@ -351,6 +378,7 @@
351378
C9DE0460242C853F008A0070 /* Config.swift in Sources */,
352379
C9ED9CE323D7F9D0004567A1 /* SourceEditorCommand.swift in Sources */,
353380
C9CEE26D242B382900A04EA9 /* YApiCreator.swift in Sources */,
381+
C92A971E24E5150600C87CCD /* Constants.swift in Sources */,
354382
);
355383
runOnlyForDeploymentPostprocessing = 0;
356384
};

SwiftJSONModeler For Xcode.xcodeproj/xcuserdata/yibin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,21 @@
5252
landmarkType = "7">
5353
</BreakpointContent>
5454
</BreakpointProxy>
55+
<BreakpointProxy
56+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
57+
<BreakpointContent
58+
uuid = "466B3471-0979-4C9D-A04B-27451E775691"
59+
shouldBeEnabled = "Yes"
60+
ignoreCount = "0"
61+
continueAfterRunningActions = "No"
62+
filePath = "SwiftJSONModeler For XcodeTests/SwiftJSONModelerTest/YApiObjectTest.swift"
63+
startingColumnNumber = "9223372036854775807"
64+
endingColumnNumber = "9223372036854775807"
65+
startingLineNumber = "41"
66+
endingLineNumber = "41"
67+
landmarkName = "testYapiRawTransformObjedt()"
68+
landmarkType = "7">
69+
</BreakpointContent>
70+
</BreakpointProxy>
5571
</Breakpoints>
5672
</Bucket>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Constants.swift
3+
// SwiftJSONModeler For Xcode
4+
//
5+
// Created by Sven on 2020/8/13.
6+
// Copyright © 2020 Sven. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
let configCommand = "config"
12+
let structFromJSONCommand = "structFromJSON"
13+
let classFromJSONCommand = "classFromJSON"
14+
let structFromRAWCommand = "structFromRAW"
15+
let classFromRAWCommand = "classFromRAW"
16+
let structFromYApiIdCommand = "structFromYApiId"
17+
let classFromYApiIdCommand = "classFromYApiId"
18+
19+
let domain = "SwiftJSONModeler"
20+
let keyImport = "import"
21+
let keyClass = "class"
22+
let keyStruct = "struct"
23+
24+
typealias CommandId = String

SwiftJSONModeler/ErrorCenter.swift renamed to SwiftJSONModeler For Xcode/ErrorCenter.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
import Foundation
1010

11+
extension Notification.Name {
12+
static let errorNotification = Notification.Name("errorNoti")
13+
}
14+
1115
class ErrorCenter {
1216
static let shared: ErrorCenter = ErrorCenter()
1317

SwiftJSONModeler/YApi/YApiCreator.swift renamed to SwiftJSONModeler For Xcode/YApi/YApiCreator.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class YApiCreator {
8282
lineObject(self.creatObjects.first!)
8383
}
8484
}
85-
/// 返回注释和每一行的
85+
/// 返回注释和每个对象的行内容(处理非 array 和 object类型)
8686
private func lineRow(from object: YApiObject) -> [String]? {
8787
let type = object.type!
8888
let config = Config()
@@ -96,9 +96,8 @@ class YApiCreator {
9696
if let temp = subObject.key?.upperCaseFirst() {
9797
swiftType = "[\(config.prefix + temp + config.subffix)]"
9898
} else {
99-
swiftType = "[<#Undefiend#>]"
99+
swiftType = "<#Undefined#>"
100100
}
101-
102101
} else {
103102
swiftType = "[\(subObjectType.swiftType())]"
104103
}
@@ -109,12 +108,18 @@ class YApiCreator {
109108
creatObjects.insert(object)
110109
swiftType = object.key!.upperCaseFirst()
111110
swiftType = config.prefix + swiftType + config.subffix
112-
case .integer, .string, .number, .boolean:
111+
case .integer, .string, .number, .boolean, .undefined:
113112
break
114113
}
115114

116115
isShowMock = config.isShowYApiMock
117-
let comment = "/// \(object.des)\(isShowMock && !object.mock.isEmpty ? "\tMock:\(object.mock)" : "")"
116+
var comment = ""
117+
if let objectDes = object.des {
118+
comment = "/// \(objectDes)\(isShowMock && !object.mock.isEmpty ? "\tMock:\(object.mock)" : "")"
119+
}
120+
if swiftType == "<#Undefined#>" {
121+
swiftType = object.typeRaw
122+
}
118123
var line = "var \(object.key!): \(swiftType)"
119124
let isOptional = !config.isNotOptional
120125
if isOptional {
@@ -144,10 +149,7 @@ class YApiCreator {
144149
if yapiObject.key != nil {
145150
name = yapiObject.key!.upperCaseFirst()
146151
}
147-
var des: String = "<#描述#>"
148-
if !yapiObject.des.isEmpty {
149-
des = yapiObject.des
150-
}
152+
let des: String = yapiObject.des ?? "<#描述#>"
151153
var keyword = keyStruct
152154
if commandIdentifier.contains(keyStruct) {
153155
keyword = keyStruct
@@ -166,7 +168,7 @@ class YApiCreator {
166168
}
167169
let lines = yapiLines.map{ "\t\($0)" }
168170
objctLines.append(contentsOf: lines)
169-
if commandIdentifier == classFromRAWCommand, parent.contains("HandyJSON") {
171+
if (commandIdentifier == classFromRAWCommand && commandIdentifier == classFromYApiIdCommand), parent.contains("HandyJSON") {
170172
objctLines.append("")
171173
objctLines.append("\trequired init() { }")
172174
}

SwiftJSONModeler/YApi/YApiHelper.swift renamed to SwiftJSONModeler For Xcode/YApi/YApiHelper.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class YApiHelper {
6161
var ob = YApiObject()
6262
ob.childs = objectsOf(key:"", properties: dic)
6363
ob.type = .object
64+
ob.typeRaw = "object"
6465
apiObj = ob
6566
}
6667
guard let object = apiObj else {
@@ -100,10 +101,10 @@ class YApiHelper {
100101

101102
// type 类型 如果不含type则为完整模型
102103
private func apiType(of dic:[String: Any]) -> YApiType? {
103-
guard let typeStr = dic["type"] as? String, let type = YApiType.of(typeStr) else {
104+
guard let typeStr = dic["type"] as? String else {
104105
return nil
105106
}
106-
return type
107+
return YApiType.of(typeStr)
107108
}
108109
private func objectsOf(key parent: String, properties: [String: Any]) -> [YApiObject] {
109110
var objectArr: [YApiObject] = []
@@ -120,6 +121,7 @@ class YApiHelper {
120121
}
121122
return objectArr
122123
}
124+
/// 获取某一具体类型的对象
123125
private func object(key: String = "", json: [String: Any]) -> YApiObject? {
124126
guard let type = apiType(of: json) else {
125127
ErrorCenter.shared.message = "key数据格式异常\n:\(json)"
@@ -128,6 +130,7 @@ class YApiHelper {
128130
var object = YApiObject()
129131
object.key = key
130132
object.type = type
133+
object.typeRaw = ((json["type"] as? String) ?? "")
131134
switch type {
132135
case .object:
133136
if let properties = json["properties"] as? [String: Any] {
@@ -138,8 +141,9 @@ class YApiHelper {
138141
}
139142

140143
case .array:
141-
if let items = json["items"] as? [String: Any], let type = items["type"] as? String, let apiType = YApiType.of(type) {
144+
if let items = json["items"] as? [String: Any], let type = items["type"] as? String {
142145
object.des = json["description"] as? String ?? ""
146+
let apiType = YApiType.of(type)
143147
if apiType == .object {
144148
if let arrObject = self.object(key: key, json: items) {
145149
object.childs = [arrObject]
@@ -154,7 +158,7 @@ class YApiHelper {
154158
ErrorCenter.shared.message = "数组\(key)异常,可能不存在items或type"
155159
return nil
156160
}
157-
case .integer, .boolean, .string, .number:
161+
case .integer, .boolean, .string, .number, .undefined:
158162
if let mockJson = json["mock"] as? [String: Any], let mock = mockJson["mock"] as? String {
159163
object.mock = mock
160164
}

SwiftJSONModeler/YApi/YApiObject.swift renamed to SwiftJSONModeler For Xcode/YApi/YApiObject.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Foundation
1111
private let keyJavaDouble = "double"
1212
private let keyJavaFloat = "float"
1313
private let keyJavaLong = "long"
14+
private let keyJavaInt = "int"
1415
/// YApi标准数据类型
1516
/// - Important: 请务必使用类方法 of()进行类型初始化
1617
enum YApiType: String {
@@ -20,6 +21,7 @@ enum YApiType: String {
2021
case boolean = "boolean"
2122
case string = "string"
2223
case number = "number"
24+
case undefined
2325
/// 对于Swift基本类型。object和arry为Undefined 则需要自行构造
2426
func swiftType() -> String {
2527
switch self {
@@ -31,27 +33,30 @@ enum YApiType: String {
3133
return "String"
3234
case .number:
3335
return "Double"
36+
case .undefined:
37+
return "<#Undefined#>"
3438
default:
3539
return "<#Undefined#>"
3640
}
3741
}
38-
39-
static func of(_ string: String) -> Self? {
42+
/// 规范化 yapi 类型
43+
static func of(_ string: String) -> Self {
4044
let lowerStr = string.lowercased() // 由于java存在基本数据类型和对象类型。
4145
if let apiType = YApiType(rawValue: lowerStr) {
4246
return apiType
4347
} else {
4448
switch lowerStr {
4549
case keyJavaLong:
4650
return .integer
47-
case keyJavaLong, keyJavaDouble:
51+
case keyJavaFloat, keyJavaDouble:
4852
return .number
53+
case keyJavaInt:
54+
return .integer
4955
default:
50-
return nil
56+
return .undefined
5157
}
5258
}
5359
}
54-
5560
}
5661
struct YApiObject: Hashable {
5762
func hash(into hasher: inout Hasher) {
@@ -66,7 +71,9 @@ struct YApiObject: Hashable {
6671
var key: String!
6772
var mock: String = ""
6873
var type: YApiType!
69-
var des: String = ""
74+
/// 原始 类型
75+
var typeRaw: String = ""
76+
var des: String?
7077
var childs: [YApiObject] = []
7178

7279

File renamed without changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// YApiObjectTest.swift
3+
// SwiftJSONModeler For XcodeTests
4+
//
5+
// Created by Sven on 2020/8/13.
6+
// Copyright © 2020 Sven. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import SwiftJSONModeler_For_Xcode
11+
12+
class YApiObjectTest: XCTestCase {
13+
14+
override func setUpWithError() throws {
15+
// Put setup code here. This method is called before the invocation of each test method in the class.
16+
}
17+
18+
override func tearDownWithError() throws {
19+
// Put teardown code here. This method is called after the invocation of each test method in the class.
20+
}
21+
22+
func testExample() throws {
23+
// This is an example of a functional test case.
24+
// Use XCTAssert and related functions to verify your tests produce the correct results.
25+
}
26+
27+
func testPerformanceExample() throws {
28+
// This is an example of a performance test case.
29+
self.measure {
30+
// Put the code you want to measure the time of here.
31+
}
32+
}
33+
///
34+
func testYapiRawTransformObjedt() -> Void {
35+
let rawStr =
36+
"""
37+
"""
38+
let helper = YApiHelper(paste: rawStr)
39+
helper.aimPath = "data"
40+
let yapiObject = helper.compleObject
41+
XCTAssertNil(yapiObject)
42+
}
43+
44+
}

0 commit comments

Comments
 (0)