-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModelInput.ts
201 lines (194 loc) · 6.8 KB
/
ModelInput.ts
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import {useShapeValidate} from "@/shape/shapeValidate.ts";
import {GenModelInput} from "@/api/__generated/model/static";
import {validateGraphData} from "@/shape/GraphData.ts";
import {GenEnumModelInputJsonSchema} from "@/shape/GenEnumModelInput.ts";
// typescript-json-schema src/api/__generated/model/static/GenModelInput.ts * --required
// 添加 ...GenEnumModelInputJsonSchema.definitions,
export const GenModelInputJsonSchema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
...GenEnumModelInputJsonSchema.definitions,
"DataSourceType": {
"enum": [
"H2",
"MySQL",
"PostgreSQL"
],
"type": "string"
},
"DatabaseNamingStrategyType": {
"enum": [
"LOWER_CASE",
"RAW",
"UPPER_CASE"
],
"type": "string"
},
"GenLanguage": {
"description": "生成语言",
"enum": [
"JAVA",
"KOTLIN"
],
"type": "string"
},
"GenModelInput": {
"properties": {
"author": {
"description": "作者",
"type": "string"
},
"columnAnnotation": {
"description": "生成 Column 注解",
"type": "boolean"
},
"columnCommentPrefixes": {
"description": "转换属性时移除的列注释前缀",
"type": "string"
},
"columnCommentSuffixes": {
"description": "转换属性时移除的列注释后缀",
"type": "string"
},
"columnNamePrefixes": {
"description": "转换属性时移除的列名前缀",
"type": "string"
},
"columnNameSuffixes": {
"description": "转换属性时移除的列名后缀",
"type": "string"
},
"dataSourceType": {
"$ref": "#/definitions/DataSourceType",
"description": "数据源类型"
},
"databaseNamingStrategy": {
"$ref": "#/definitions/DatabaseNamingStrategyType",
"description": "数据库命名策略"
},
"enums": {
"description": "枚举",
"items": {
"$ref": "#/definitions/GenModelInput_TargetOf_enums"
},
"type": "array"
},
"graphData": {
"description": "Graph 数据",
"type": "string"
},
"id": {
"description": "ID",
"type": "number"
},
"idViewProperty": {
"description": "生成 IdView 属性",
"type": "boolean"
},
"joinColumnAnnotation": {
"description": "生成 JoinColumn 注解",
"type": "boolean"
},
"joinTableAnnotation": {
"description": "生成 JoinTable 注解",
"type": "boolean"
},
"language": {
"$ref": "#/definitions/GenLanguage",
"description": "语言"
},
"logicalDeletedAnnotation": {
"description": "逻辑删除注解",
"type": "string"
},
"name": {
"description": "名称",
"type": "string"
},
"packagePath": {
"description": "包路径",
"type": "string"
},
"realFk": {
"description": "启用真实外键",
"type": "boolean"
},
"remark": {
"description": "备注",
"type": "string"
},
"tableAnnotation": {
"description": "生成 Table 注解",
"type": "boolean"
},
"tableCommentPrefixes": {
"description": "转换实体时移除的表注释前缀",
"type": "string"
},
"tableCommentSuffixes": {
"description": "转换实体时移除的表注释后缀",
"type": "string"
},
"tableNamePrefixes": {
"description": "转换实体时移除的表名前缀",
"type": "string"
},
"tableNameSuffixes": {
"description": "转换实体时移除的表名后缀",
"type": "string"
},
"tablePath": {
"description": "表路径",
"type": "string"
}
},
"required": [
"author",
"columnAnnotation",
"columnCommentPrefixes",
"columnCommentSuffixes",
"columnNamePrefixes",
"columnNameSuffixes",
"dataSourceType",
"databaseNamingStrategy",
"enums",
"idViewProperty",
"joinColumnAnnotation",
"joinTableAnnotation",
"language",
"logicalDeletedAnnotation",
"name",
"packagePath",
"realFk",
"remark",
"tableAnnotation",
"tableCommentPrefixes",
"tableCommentSuffixes",
"tableNamePrefixes",
"tableNameSuffixes",
"tablePath"
],
"type": "object"
}
}
}
const {validate: validateModelInputJson} =
useShapeValidate<GenModelInput>(
"GenModelInput",
GenModelInputJsonSchema
)
export const validateModelInput = (data: any, onErrors: (e: any) => void) => {
const result = validateModelInputJson(data, onErrors)
if (result) {
if ("graphData" in data) {
return validateGraphData(JSON.parse(data["graphData"]), onErrors)
} else {
return result
}
}
return result
}
export const validateModelInputStr = (jsonStr: string, onErrors: (e: any) => void) => {
const modelInput = JSON.parse(jsonStr)
return validateModelInput(modelInput, onErrors)
}