Skip to content

Commit e394f41

Browse files
author
Sven
committed
Merge branch 'master' into release
* master: (27 commits) update update feat: 添加 remark 用于记多个 token fix some bug doc: 添加 Unit 测试单元 refact: 文件目录调整,准备添加测试用例 style: update version to 1.3.0 fix: 兼容Java 基本数据类型和对象数据类型。 fix: 解决通过YApi 接口Id不能转模问题[数据类型不是标准的类型兼容。比如String, Long, Integer] feat: feat: YApi 通过Id转模支持。 feat: 增加支持Yapi 通过 id 转换模型 feat: 添加支持 YApi RAW数据转模功能。 feat: 添加yapi 支持指定path 解析 优化 fix: 添加Config文件 update windows 复合整理。 优化。 ... # Conflicts: # README.md
2 parents 040b8fa + 5aa0f9e commit e394f41

31 files changed

+1774
-146
lines changed

README.md

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
SwiftJSONModeler是一个Xcode插件,可以将json 转为模型
1+
SwiftJSONModeler是一个Xcode插件,可以将json 转为Swfit模型
22
* 支持struct, class
3-
* 所有值为可选
4-
* 支持自定义遵循 和 import
3+
* 支持单json转模
4+
* 支持YApi RAW或接口id解析转模,并且自动添加注释
5+
* 支持自定义遵循 和 import
6+
* 支持自定义模型前缀和后缀
7+
* 可设置是否类型可选,是否使用显示可选`?`(不使用则为隐式可选`!`)
8+
* YApi RWA支持按照路径解析模型,自动解析子类型
59

610
## 效果图
711

12+
### 标准json 解析
13+
14+
复制单json, 一步转为模型。
15+
816
![运行效果](./Sources/example.gif)
9-
如果无法预览查看[传输门](https://github.com/yumengqing/SwiftJSONModeler/blob/master/Sources/example.gif)
17+
18+
19+
如果无法预览查看[传输门](https://github.com/yumengqing/SwiftJSONModeler/blob/master/Sources/example.gif)或者[Sources/example.gif](./Sources/example.gif)
20+
21+
### YApi RAW解析
22+
23+
复制YApi接口RAW数据,一步解析带有注释的模型。
24+
解析效果如下():
25+
26+
![解析YApi](./Sources/YApiRAW.gif)
27+
28+
如果无法预览查看[Source/YApiRAW.gif](./Sources/YApiRAW.gif)
29+
1030
## 安装
1131
1.你可以选择[Release](https://github.com/yumengqing/SwiftJSONModeler/releases) 直接下载应用安装
1232

@@ -25,28 +45,36 @@ SwiftJSONModeler是一个Xcode插件,可以将json 转为模型
2545

2646
> Tip:如果重启Xcode之后在Editor中还没看见插件选项,请选择系统设置-> 扩展->Xcode Source Editor中对应插件是否导入
2747
28-
### 设置快捷键
48+
## 设置
49+
SwiftJSONModeler提供多种自定义可选设置,可通过插件的Config选项进行设置。
2950

30-
可以给插件设置快捷键,快速转换模型
51+
设置选项如下图:
3152

32-
在Xcode -> Preference -> Key Bindings -> Editor Menu For Source Code【或者搜索】就可以找到,如下图
53+
![可选设置](./Sources/config.png)
3354

34-
![](./Sources/keybinding.png)
55+
**YApi模型路径指定**:当对象含有多层json,或者有基本json包裹时,可以指定path解析模型。
3556

36-
记得双击key下面那个区域才可以编辑,这里我使用的是alt + s 和alt + c 避免与系统的冲突
57+
**YApi项目token**: 每个YApi项目都有唯一一个token,在YApi项目接口的设置中可以查看对应的token,如下图:
58+
59+
![token](./Sources/yapiToken.png)
60+
61+
**YApi项目host**:host就是部署YApi的地址
3762

38-
### 自定义操作confrom 和import
63+
![host](./Sources/yapiHostId.png)
3964

40-
可以通过点击应用或者选择扩展的config选项,自定义填写import模块和继承
65+
## 设置快捷键
4166

42-
比如我需要继承HandyJSON
67+
可以给插件设置快捷键,快速转换模型
4368

44-
![自定义遵循](./Sources/customConfig.png)
69+
在Xcode -> Preference -> Key Bindings -> Editor Menu For Source Code【或者搜索】就可以找到,如下图
4570

71+
![](./Sources/keybinding.png)
4672

47-
## 使用
73+
记得双击key下面那个区域才可以编辑,这里我使用的是alt + s 和alt + c 避免与系统的冲突
74+
## 标准JSON转模
4875

49-
使用的使用,首先要选中需要转换的json,注意不标准的json会报错的哟。仅限单层json,多层json子json需要单独转换
76+
复制需要转换的json,选择插件的Struct JSON或者Class JSON功能,即可生成相应Swift模型。
77+
注意:目前只支持单层json
5078

5179
示例json
5280

@@ -85,5 +113,40 @@ struct <#Model#>: HandyJSON {
85113

86114
![效果图](./Sources/result.png)
87115

116+
## YApi 接口平台转模
117+
118+
如果你使用YApi接口平台,可以通过复制接口返回的 RAW数据,或者复制Id,自动转为模型,并且自动根据YApi为模型添加注释。
119+
120+
### 通过Id转模
121+
122+
在配置了项目token和host基础下,简单复制Id即可实现转模和添加注释.
123+
124+
**如何查看YApi接口中的id?**在YApi对应的接口中,查看浏览器网址,最后的数字就是Id。如下图:
125+
126+
![接口Id](./Sources/yapiHostId.png)
127+
128+
129+
130+
### RAW数据
131+
132+
**RAW数据**:即YApi接口平台提供的带有接口字段及注释的json数据,查看方式:选择接口 -> 编辑 -> 返回数据设置 -> RAW 如下图
133+
134+
![Alt](./Sources/YApiRAWData.png)
135+
136+
示例RAW数据:
137+
138+
```javascript
139+
{"type":"object","title":"empty object","properties":{"message":{"type":"string"},"code":{"type":"string"},"response":{"type":"object","properties":{"teachers":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string","mock":{"mock":"Mrs Yang"},"description":"名字"},"subject":{"type":"string","mock":{"mock":"语文"},"description":"科目"},"phone":{"type":"string","mock":{"mock":"13459923098"},"description":"联系电话"}},"required":["name","subject","phone"]},"description":"老师"},"name":{"type":"string","description":"姓名"},"age":{"type":"integer","mock":{"mock":"18"},"description":"年龄"},"score":{"type":"number","mock":{"mock":"89.8"},"description":"综合成绩"},"likes":{"type":"array","items":{"type":"string","mock":{"mock":"英雄联盟"}},"description":"爱好"},"emergercyContact":{"type":"object","properties":{"name":{"type":"string"},"phone":{"type":"string","description":"联系电话"},"address":{"type":"string","description":"联系地址","mock":{"mock":"xx街道xx栋xx单元"}}},"description":"紧急联系人","required":["name","phone","address"]},"isBoy":{"type":"boolean","description":"是否为男孩"}},"required":["teachers","name","age","score","likes","emergercyContact","isBoy"]}},"required":["message","code","response"]}
140+
```
141+
142+
> 完整示例可下载打开SwiftJSONModelerDemo查看
143+
144+
### 解析指定路径模型
145+
146+
如果你数据有多层json, 可以在设置中指定解析路线path来获取指定模型。比如我的目标数据在response字段下,则可以配置path为response.则直接解析response下的json模型。多路径使用 `.`
147+
148+
149+
88150
## 待优化
151+
89152
* 直接解析出子json 或者 数组内子json

Sources/YApiRAW.gif

17.7 MB
Loading

Sources/YApiRAWData.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/YApiRAWData.png

46.6 KB
Loading

Sources/config.png

214 KB
Loading

Sources/customConfig.png

-54.4 KB
Binary file not shown.

Sources/yapiHostId.png

27.2 KB
Loading

Sources/yapiToken.png

149 KB
Loading

0 commit comments

Comments
 (0)