pg-mvc-service 2.0.114 → 2.0.116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -722,10 +722,10 @@ class RequestType extends ReqResType_1.default {
|
|
|
722
722
|
}
|
|
723
723
|
const numberValue = Number(value);
|
|
724
724
|
if (property.min !== undefined && numberValue < property.min) {
|
|
725
|
-
this.throwInputError(isRequestBody ? "
|
|
725
|
+
this.throwInputError(isRequestBody ? "NUMBER_22" : "NUMBER_92", keys, value);
|
|
726
726
|
}
|
|
727
727
|
if (property.max !== undefined && numberValue > property.max) {
|
|
728
|
-
this.throwInputError(isRequestBody ? "
|
|
728
|
+
this.throwInputError(isRequestBody ? "NUMBER_23" : "NUMBER_93", keys, value);
|
|
729
729
|
}
|
|
730
730
|
return numberValue;
|
|
731
731
|
case 'boolean':
|
|
@@ -1022,7 +1022,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
1022
1022
|
return ymlString;
|
|
1023
1023
|
}
|
|
1024
1024
|
getInputErrorList(method, code) {
|
|
1025
|
-
|
|
1025
|
+
let errorList = [];
|
|
1026
1026
|
for (const [key, property] of Object.entries(this.properties)) {
|
|
1027
1027
|
if (property.type.endsWith('?') === false) {
|
|
1028
1028
|
const errorCode = property.type === 'array' && ['GET', 'DELETE'].includes(method) ? 'REQUIRE_00' : 'REQUIRE_01';
|
|
@@ -1040,6 +1040,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
1040
1040
|
code: code + '-OBJECT_01',
|
|
1041
1041
|
description: this.createErrorMessage('OBJECT_01', [key])
|
|
1042
1042
|
});
|
|
1043
|
+
errorList = [...errorList, ...this.getErrorObject([key], code)];
|
|
1043
1044
|
break;
|
|
1044
1045
|
case 'array':
|
|
1045
1046
|
case 'array?':
|
|
@@ -1048,6 +1049,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
1048
1049
|
code: code + '-ARRAY_01',
|
|
1049
1050
|
description: this.createErrorMessage('ARRAY_01', [key])
|
|
1050
1051
|
});
|
|
1052
|
+
errorList = [...errorList, ...this.getErrorArray([key], code)];
|
|
1051
1053
|
break;
|
|
1052
1054
|
case 'map':
|
|
1053
1055
|
case 'map?':
|
|
@@ -1085,22 +1087,305 @@ class RequestType extends ReqResType_1.default {
|
|
|
1085
1087
|
break;
|
|
1086
1088
|
}
|
|
1087
1089
|
break;
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
+
default:
|
|
1091
|
+
errorList = [...errorList, ...this.getError([key], code, true)];
|
|
1092
|
+
break;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return errorList;
|
|
1096
|
+
}
|
|
1097
|
+
getErrorObject(keys, code) {
|
|
1098
|
+
let errorList = [];
|
|
1099
|
+
const property = this.getProperty(keys);
|
|
1100
|
+
if (property.type !== 'object' && property.type !== 'object?') {
|
|
1101
|
+
throw new Error(`sgetErrorObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
1102
|
+
}
|
|
1103
|
+
for (const key of Object.keys(property.properties)) {
|
|
1104
|
+
if (property.properties[key].type.endsWith('?') === false) {
|
|
1105
|
+
this.throwInputError("REQUIRE_11", [...keys, key], "");
|
|
1106
|
+
}
|
|
1107
|
+
switch (property.properties[key].type) {
|
|
1108
|
+
case 'object':
|
|
1109
|
+
case 'object?':
|
|
1110
|
+
errorList.push({
|
|
1111
|
+
status: 400,
|
|
1112
|
+
code: code + '-OBJECT_11',
|
|
1113
|
+
description: this.createErrorMessage('OBJECT_11', [...keys, key]),
|
|
1114
|
+
});
|
|
1115
|
+
errorList = [...errorList, ...this.getErrorObject([...keys, key], code)];
|
|
1116
|
+
break;
|
|
1117
|
+
case 'array':
|
|
1118
|
+
case 'array?':
|
|
1119
|
+
errorList.push({
|
|
1120
|
+
status: 400,
|
|
1121
|
+
code: code + '-ARRAY_11',
|
|
1122
|
+
description: this.createErrorMessage('ARRAY_11', [...keys, key]),
|
|
1123
|
+
});
|
|
1124
|
+
errorList = [...errorList, ...this.getErrorArray([key], code)];
|
|
1125
|
+
break;
|
|
1126
|
+
case 'map':
|
|
1127
|
+
case 'map?':
|
|
1128
|
+
switch (property.properties[key].mapType) {
|
|
1129
|
+
case 'number':
|
|
1130
|
+
errorList.push({
|
|
1131
|
+
status: 400,
|
|
1132
|
+
code: code + '-MAP_11',
|
|
1133
|
+
description: this.createErrorMessage('MAP_11', [key])
|
|
1134
|
+
});
|
|
1135
|
+
break;
|
|
1136
|
+
case 'string':
|
|
1137
|
+
errorList.push({
|
|
1138
|
+
status: 400,
|
|
1139
|
+
code: code + '-MAP_12',
|
|
1140
|
+
description: this.createErrorMessage('MAP_12', [key])
|
|
1141
|
+
});
|
|
1142
|
+
break;
|
|
1143
|
+
case 'bool':
|
|
1144
|
+
errorList.push({
|
|
1145
|
+
status: 400,
|
|
1146
|
+
code: code + '-MAP_13',
|
|
1147
|
+
description: this.createErrorMessage('MAP_13', [key])
|
|
1148
|
+
});
|
|
1149
|
+
errorList.push({
|
|
1150
|
+
status: 400,
|
|
1151
|
+
code: code + '-MAP_14',
|
|
1152
|
+
description: this.createErrorMessage('MAP_14', [key])
|
|
1153
|
+
});
|
|
1154
|
+
errorList.push({
|
|
1155
|
+
status: 400,
|
|
1156
|
+
code: code + '-MAP_15',
|
|
1157
|
+
description: this.createErrorMessage('MAP_15', [key])
|
|
1158
|
+
});
|
|
1159
|
+
break;
|
|
1160
|
+
}
|
|
1090
1161
|
break;
|
|
1091
1162
|
default:
|
|
1163
|
+
errorList = [...errorList, ...this.getError([...keys, key], code, false)];
|
|
1092
1164
|
break;
|
|
1093
1165
|
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1166
|
+
}
|
|
1167
|
+
return errorList;
|
|
1168
|
+
}
|
|
1169
|
+
getErrorArray(keys, code) {
|
|
1170
|
+
let errorList = [];
|
|
1171
|
+
const property = this.getProperty(keys);
|
|
1172
|
+
if (property.type !== 'array' && property.type !== 'array?') {
|
|
1173
|
+
throw new Error(`setArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
1174
|
+
}
|
|
1175
|
+
errorList.push({
|
|
1176
|
+
status: 400,
|
|
1177
|
+
code: code + '-REQUIRE_31',
|
|
1178
|
+
description: this.createErrorMessage('REQUIRE_31', [...keys]),
|
|
1179
|
+
});
|
|
1180
|
+
switch (property.item.type) {
|
|
1181
|
+
case 'object':
|
|
1182
|
+
case 'object?':
|
|
1183
|
+
errorList = [...errorList, ...this.getErrorObject([...keys, 0], code)];
|
|
1184
|
+
break;
|
|
1185
|
+
case 'array':
|
|
1186
|
+
case 'array?':
|
|
1187
|
+
errorList = [...errorList, ...this.getErrorArray([...keys, 0], code)];
|
|
1188
|
+
break;
|
|
1189
|
+
case 'map':
|
|
1190
|
+
case 'map?':
|
|
1191
|
+
switch (property.item.mapType) {
|
|
1192
|
+
case 'number':
|
|
1193
|
+
errorList.push({
|
|
1194
|
+
status: 400,
|
|
1195
|
+
code: code + '-MAP_11',
|
|
1196
|
+
description: this.createErrorMessage('MAP_31', [...keys, 0])
|
|
1197
|
+
});
|
|
1198
|
+
break;
|
|
1199
|
+
case 'string':
|
|
1200
|
+
errorList.push({
|
|
1201
|
+
status: 400,
|
|
1202
|
+
code: code + '-MAP_12',
|
|
1203
|
+
description: this.createErrorMessage('MAP_32', [...keys, 0])
|
|
1204
|
+
});
|
|
1205
|
+
break;
|
|
1206
|
+
case 'bool':
|
|
1207
|
+
errorList.push({
|
|
1208
|
+
status: 400,
|
|
1209
|
+
code: code + '-MAP_13',
|
|
1210
|
+
description: this.createErrorMessage('MAP_33', [...keys, 0])
|
|
1211
|
+
});
|
|
1212
|
+
errorList.push({
|
|
1213
|
+
status: 400,
|
|
1214
|
+
code: code + '-MAP_14',
|
|
1215
|
+
description: this.createErrorMessage('MAP_34', [...keys, 0])
|
|
1216
|
+
});
|
|
1217
|
+
errorList.push({
|
|
1218
|
+
status: 400,
|
|
1219
|
+
code: code + '-MAP_15',
|
|
1220
|
+
description: this.createErrorMessage('MAP_35', [...keys, 0])
|
|
1221
|
+
});
|
|
1222
|
+
break;
|
|
1223
|
+
}
|
|
1224
|
+
break;
|
|
1225
|
+
default:
|
|
1226
|
+
errorList = [...errorList, ...this.getError([...keys, 0], code, false)];
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
return errorList;
|
|
1230
|
+
}
|
|
1231
|
+
getError(keys, code, isRequestBody) {
|
|
1232
|
+
const errorList = [];
|
|
1233
|
+
const property = this.getProperty(keys);
|
|
1234
|
+
switch (property.type) {
|
|
1235
|
+
case 'enum':
|
|
1236
|
+
case 'enum?':
|
|
1237
|
+
switch (property.enumType) {
|
|
1238
|
+
case 'number':
|
|
1239
|
+
case 'number?':
|
|
1240
|
+
errorList.push({
|
|
1241
|
+
status: 400,
|
|
1242
|
+
code: code + '-NUMBER_41',
|
|
1243
|
+
description: this.createErrorMessage('NUMBER_41', keys)
|
|
1244
|
+
});
|
|
1245
|
+
break;
|
|
1246
|
+
case 'string':
|
|
1247
|
+
case 'string?':
|
|
1248
|
+
errorList.push({
|
|
1249
|
+
status: 400,
|
|
1250
|
+
code: code + '-STRING_41',
|
|
1251
|
+
description: this.createErrorMessage('STRING_41', keys)
|
|
1252
|
+
});
|
|
1253
|
+
break;
|
|
1254
|
+
}
|
|
1255
|
+
errorList.push({
|
|
1256
|
+
status: 400,
|
|
1257
|
+
code: code + '-ENUM_42',
|
|
1258
|
+
description: this.createErrorMessage('ENUM_42', keys)
|
|
1259
|
+
});
|
|
1260
|
+
break;
|
|
1261
|
+
case 'number':
|
|
1262
|
+
case 'number?':
|
|
1263
|
+
errorList.push({
|
|
1264
|
+
status: 400,
|
|
1265
|
+
code: isRequestBody ? code + "-NUMBER_21" : code + "-NUMBER_91",
|
|
1266
|
+
description: this.createErrorMessage(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys)
|
|
1267
|
+
});
|
|
1268
|
+
if (property.min !== undefined) {
|
|
1269
|
+
errorList.push({
|
|
1270
|
+
status: 400,
|
|
1271
|
+
code: isRequestBody ? code + "-NUMBER_22" : code + "-NUMBER_92",
|
|
1272
|
+
description: this.createErrorMessage(isRequestBody ? "NUMBER_22" : "NUMBER_92", keys)
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
if (property.max !== undefined) {
|
|
1276
|
+
errorList.push({
|
|
1277
|
+
status: 400,
|
|
1278
|
+
code: isRequestBody ? code + "-NUMBER_23" : code + "-NUMBER_93",
|
|
1279
|
+
description: this.createErrorMessage(isRequestBody ? "NUMBER_23" : "NUMBER_93", keys)
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
break;
|
|
1283
|
+
case 'boolean':
|
|
1284
|
+
case 'boolean?':
|
|
1285
|
+
errorList.push({
|
|
1286
|
+
status: 400,
|
|
1287
|
+
code: isRequestBody ? code + "-BOOL_21" : code + "-BOOL_91",
|
|
1288
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_21" : "BOOL_91", keys)
|
|
1289
|
+
});
|
|
1290
|
+
errorList.push({
|
|
1291
|
+
status: 400,
|
|
1292
|
+
code: isRequestBody ? code + "-BOOL_22" : code + "-BOOL_92",
|
|
1293
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_22" : "BOOL_92", keys)
|
|
1294
|
+
});
|
|
1295
|
+
errorList.push({
|
|
1296
|
+
status: 400,
|
|
1297
|
+
code: isRequestBody ? code + "-BOOL_23" : code + "-BOOL_93",
|
|
1298
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
|
|
1299
|
+
});
|
|
1300
|
+
break;
|
|
1301
|
+
case 'string':
|
|
1302
|
+
case 'string?':
|
|
1303
|
+
errorList.push({
|
|
1304
|
+
status: 400,
|
|
1305
|
+
code: isRequestBody ? code + "-STRING_21" : code + "-STRING_91",
|
|
1306
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
|
|
1307
|
+
});
|
|
1308
|
+
if (property.maxLength !== undefined) {
|
|
1309
|
+
errorList.push({
|
|
1310
|
+
status: 400,
|
|
1311
|
+
code: isRequestBody ? code + "-STRING_22" : code + "-STRING_92",
|
|
1312
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
if (property.regExp !== undefined) {
|
|
1316
|
+
errorList.push({
|
|
1317
|
+
status: 400,
|
|
1318
|
+
code: isRequestBody ? code + "-STRING_23" : code + "-STRING_93",
|
|
1319
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
break;
|
|
1323
|
+
case 'uuid':
|
|
1324
|
+
case 'uuid?':
|
|
1325
|
+
errorList.push({
|
|
1326
|
+
status: 400,
|
|
1327
|
+
code: isRequestBody ? code + "-UUID_21" : code + "-UUID_91",
|
|
1328
|
+
description: this.createErrorMessage(isRequestBody ? "UUID_21" : "UUID_91", keys)
|
|
1329
|
+
});
|
|
1330
|
+
break;
|
|
1331
|
+
case 'mail':
|
|
1332
|
+
case 'mail?':
|
|
1333
|
+
errorList.push({
|
|
1334
|
+
status: 400,
|
|
1335
|
+
code: isRequestBody ? code + "-MAIL_21" : code + "-MAIL_91",
|
|
1336
|
+
description: this.createErrorMessage(isRequestBody ? "MAIL_21" : "MAIL_91", keys)
|
|
1337
|
+
});
|
|
1338
|
+
break;
|
|
1339
|
+
case 'date':
|
|
1340
|
+
case 'date?':
|
|
1341
|
+
errorList.push({
|
|
1342
|
+
status: 400,
|
|
1343
|
+
code: isRequestBody ? code + "-DATE_21" : code + "-DATE_91",
|
|
1344
|
+
description: this.createErrorMessage(isRequestBody ? "DATE_21" : "DATE_91", keys)
|
|
1345
|
+
});
|
|
1346
|
+
errorList.push({
|
|
1347
|
+
status: 400,
|
|
1348
|
+
code: isRequestBody ? code + "-DATE_22" : code + "-DATE_92",
|
|
1349
|
+
description: this.createErrorMessage(isRequestBody ? "DATE_22" : "DATE_92", keys)
|
|
1350
|
+
});
|
|
1351
|
+
break;
|
|
1352
|
+
case 'time':
|
|
1353
|
+
case 'time?':
|
|
1354
|
+
errorList.push({
|
|
1355
|
+
status: 400,
|
|
1356
|
+
code: isRequestBody ? code + "-TIME_21" : code + "-TIME_91",
|
|
1357
|
+
description: this.createErrorMessage(isRequestBody ? "TIME_21" : "TIME_91", keys)
|
|
1358
|
+
});
|
|
1359
|
+
break;
|
|
1360
|
+
case 'datetime':
|
|
1361
|
+
case 'datetime?':
|
|
1362
|
+
errorList.push({
|
|
1363
|
+
status: 400,
|
|
1364
|
+
code: isRequestBody ? code + "-DATETIME_21" : code + "-DATETIME_91",
|
|
1365
|
+
description: this.createErrorMessage(isRequestBody ? "DATETIME_21" : "DATETIME_91", keys)
|
|
1366
|
+
});
|
|
1367
|
+
errorList.push({
|
|
1368
|
+
status: 400,
|
|
1369
|
+
code: isRequestBody ? code + "-DATETIME_22" : code + "-DATETIME_92",
|
|
1370
|
+
description: this.createErrorMessage(isRequestBody ? "DATETIME_22" : "DATETIME_92", keys)
|
|
1371
|
+
});
|
|
1372
|
+
break;
|
|
1373
|
+
case 'https':
|
|
1374
|
+
case 'https?':
|
|
1375
|
+
errorList.push({
|
|
1376
|
+
status: 400,
|
|
1377
|
+
code: isRequestBody ? code + "-HTTPS_21" : code + "-HTTPS_91",
|
|
1378
|
+
description: this.createErrorMessage(isRequestBody ? "HTTPS_21" : "HTTPS_91", keys)
|
|
1379
|
+
});
|
|
1380
|
+
break;
|
|
1381
|
+
case 'base64':
|
|
1382
|
+
case 'base64?':
|
|
1383
|
+
errorList.push({
|
|
1384
|
+
status: 400,
|
|
1385
|
+
code: isRequestBody ? code + "-BASE64_21" : code + "-BASE64_91",
|
|
1386
|
+
description: this.createErrorMessage(isRequestBody ? "BASE64_21" : "BASE64_91", keys)
|
|
1387
|
+
});
|
|
1388
|
+
break;
|
|
1104
1389
|
}
|
|
1105
1390
|
return errorList;
|
|
1106
1391
|
}
|
|
@@ -394,12 +394,12 @@ class ResponseType extends ReqResType_1.default {
|
|
|
394
394
|
if (list.length === 1) {
|
|
395
395
|
// 単一エラーは1行説明
|
|
396
396
|
ymlString += ` '${status}':
|
|
397
|
-
description: ${list[0].code
|
|
397
|
+
description: ${list[0].description}${list[0].code !== '' ? ` [${list[0].code}]` : ''}
|
|
398
398
|
`;
|
|
399
399
|
}
|
|
400
400
|
else {
|
|
401
401
|
// 複数エラーは箇条書き
|
|
402
|
-
const bullets = list.map(e => `- ${e.code !== '' ?
|
|
402
|
+
const bullets = list.map(e => `- ${e.description}${e.code !== '' ? ` [${e.code}]` : ''}`).join(descIndentJoin);
|
|
403
403
|
ymlString += ` '${status}':
|
|
404
404
|
description: |${descIndentJoin}${bullets}
|
|
405
405
|
`;
|
package/package.json
CHANGED
|
@@ -789,11 +789,11 @@ export class RequestType extends ReqResType {
|
|
|
789
789
|
}
|
|
790
790
|
const numberValue = Number(value);
|
|
791
791
|
if (property.min !== undefined && numberValue < property.min) {
|
|
792
|
-
this.throwInputError(isRequestBody ? "
|
|
792
|
+
this.throwInputError(isRequestBody ? "NUMBER_22" : "NUMBER_92", keys, value);
|
|
793
793
|
}
|
|
794
794
|
|
|
795
795
|
if (property.max !== undefined && numberValue > property.max) {
|
|
796
|
-
this.throwInputError(isRequestBody ? "
|
|
796
|
+
this.throwInputError(isRequestBody ? "NUMBER_23" : "NUMBER_93", keys, value);
|
|
797
797
|
}
|
|
798
798
|
return numberValue;
|
|
799
799
|
case 'boolean':
|
|
@@ -1123,7 +1123,7 @@ export class RequestType extends ReqResType {
|
|
|
1123
1123
|
}
|
|
1124
1124
|
|
|
1125
1125
|
public getInputErrorList(method: string, code: string): Array<IError> {
|
|
1126
|
-
|
|
1126
|
+
let errorList: Array<IError> = [];
|
|
1127
1127
|
for (const [key, property] of Object.entries(this.properties)) {
|
|
1128
1128
|
if (property.type.endsWith('?') === false) {
|
|
1129
1129
|
const errorCode = property.type === 'array' && ['GET', 'DELETE'].includes(method) ? 'REQUIRE_00' : 'REQUIRE_01';
|
|
@@ -1142,6 +1142,8 @@ export class RequestType extends ReqResType {
|
|
|
1142
1142
|
code: code + '-OBJECT_01',
|
|
1143
1143
|
description: this.createErrorMessage('OBJECT_01', [key])
|
|
1144
1144
|
});
|
|
1145
|
+
|
|
1146
|
+
errorList = [...errorList, ...this.getErrorObject([key], code)];
|
|
1145
1147
|
break;
|
|
1146
1148
|
case 'array':
|
|
1147
1149
|
case 'array?':
|
|
@@ -1150,6 +1152,8 @@ export class RequestType extends ReqResType {
|
|
|
1150
1152
|
code: code + '-ARRAY_01',
|
|
1151
1153
|
description: this.createErrorMessage('ARRAY_01', [key])
|
|
1152
1154
|
});
|
|
1155
|
+
|
|
1156
|
+
errorList = [...errorList, ...this.getErrorArray([key], code)];
|
|
1153
1157
|
break;
|
|
1154
1158
|
case 'map':
|
|
1155
1159
|
case 'map?':
|
|
@@ -1187,23 +1191,323 @@ export class RequestType extends ReqResType {
|
|
|
1187
1191
|
break;
|
|
1188
1192
|
}
|
|
1189
1193
|
break;
|
|
1190
|
-
|
|
1191
|
-
|
|
1194
|
+
default:
|
|
1195
|
+
errorList = [...errorList, ...this.getError([key], code, true)];
|
|
1196
|
+
break;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
return errorList;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
private getErrorObject(keys: Array<string | number>, code: string): Array<IError> {
|
|
1204
|
+
let errorList: Array<IError> = [];
|
|
1205
|
+
|
|
1206
|
+
const property = this.getProperty(keys);
|
|
1207
|
+
if (property.type !== 'object' && property.type !== 'object?') {
|
|
1208
|
+
throw new Error(`sgetErrorObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
for (const key of Object.keys(property.properties)) {
|
|
1212
|
+
if (property.properties[key].type.endsWith('?') === false) {
|
|
1213
|
+
this.throwInputError("REQUIRE_11", [...keys, key], "");
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
switch (property.properties[key].type) {
|
|
1217
|
+
case 'object':
|
|
1218
|
+
case 'object?':
|
|
1219
|
+
errorList.push({
|
|
1220
|
+
status: 400,
|
|
1221
|
+
code: code + '-OBJECT_11',
|
|
1222
|
+
description: this.createErrorMessage('OBJECT_11', [...keys, key]),
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
errorList = [...errorList, ...this.getErrorObject([...keys, key], code)];
|
|
1226
|
+
break;
|
|
1227
|
+
case 'array':
|
|
1228
|
+
case 'array?':
|
|
1229
|
+
errorList.push({
|
|
1230
|
+
status: 400,
|
|
1231
|
+
code: code + '-ARRAY_11',
|
|
1232
|
+
description: this.createErrorMessage('ARRAY_11', [...keys, key]),
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
errorList = [...errorList, ...this.getErrorArray([key], code)];
|
|
1236
|
+
break;
|
|
1237
|
+
case 'map':
|
|
1238
|
+
case 'map?':
|
|
1239
|
+
switch (property.properties[key].mapType) {
|
|
1240
|
+
case 'number':
|
|
1241
|
+
errorList.push({
|
|
1242
|
+
status: 400,
|
|
1243
|
+
code: code + '-MAP_11',
|
|
1244
|
+
description: this.createErrorMessage('MAP_11', [key])
|
|
1245
|
+
});
|
|
1246
|
+
break;
|
|
1247
|
+
case 'string':
|
|
1248
|
+
errorList.push({
|
|
1249
|
+
status: 400,
|
|
1250
|
+
code: code + '-MAP_12',
|
|
1251
|
+
description: this.createErrorMessage('MAP_12', [key])
|
|
1252
|
+
});
|
|
1253
|
+
break;
|
|
1254
|
+
case 'bool':
|
|
1255
|
+
errorList.push({
|
|
1256
|
+
status: 400,
|
|
1257
|
+
code: code + '-MAP_13',
|
|
1258
|
+
description: this.createErrorMessage('MAP_13', [key])
|
|
1259
|
+
});
|
|
1260
|
+
errorList.push({
|
|
1261
|
+
status: 400,
|
|
1262
|
+
code: code + '-MAP_14',
|
|
1263
|
+
description: this.createErrorMessage('MAP_14', [key])
|
|
1264
|
+
});
|
|
1265
|
+
errorList.push({
|
|
1266
|
+
status: 400,
|
|
1267
|
+
code: code + '-MAP_15',
|
|
1268
|
+
description: this.createErrorMessage('MAP_15', [key])
|
|
1269
|
+
});
|
|
1270
|
+
break;
|
|
1271
|
+
}
|
|
1192
1272
|
break;
|
|
1193
1273
|
default:
|
|
1274
|
+
errorList = [...errorList, ...this.getError([...keys, key], code, false)];
|
|
1194
1275
|
break;
|
|
1195
1276
|
}
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
return errorList;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
private getErrorArray(keys: Array<string | number>, code: string) {
|
|
1283
|
+
let errorList: Array<IError> = [];
|
|
1284
|
+
|
|
1285
|
+
const property = this.getProperty(keys);
|
|
1286
|
+
if (property.type !== 'array' && property.type !== 'array?') {
|
|
1287
|
+
throw new Error(`setArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
errorList.push({
|
|
1291
|
+
status: 400,
|
|
1292
|
+
code: code + '-REQUIRE_31',
|
|
1293
|
+
description: this.createErrorMessage('REQUIRE_31', [...keys]),
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
switch (property.item.type) {
|
|
1297
|
+
case 'object':
|
|
1298
|
+
case 'object?':
|
|
1299
|
+
errorList = [...errorList, ...this.getErrorObject([...keys, 0], code)];
|
|
1300
|
+
break;
|
|
1301
|
+
case 'array':
|
|
1302
|
+
case 'array?':
|
|
1303
|
+
errorList = [...errorList, ...this.getErrorArray([...keys, 0], code)];
|
|
1304
|
+
break;
|
|
1305
|
+
case 'map':
|
|
1306
|
+
case 'map?':
|
|
1307
|
+
switch (property.item.mapType) {
|
|
1308
|
+
case 'number':
|
|
1309
|
+
errorList.push({
|
|
1310
|
+
status: 400,
|
|
1311
|
+
code: code + '-MAP_11',
|
|
1312
|
+
description: this.createErrorMessage('MAP_31', [...keys, 0])
|
|
1313
|
+
});
|
|
1314
|
+
break;
|
|
1315
|
+
case 'string':
|
|
1316
|
+
errorList.push({
|
|
1317
|
+
status: 400,
|
|
1318
|
+
code: code + '-MAP_12',
|
|
1319
|
+
description: this.createErrorMessage('MAP_32', [...keys, 0])
|
|
1320
|
+
});
|
|
1321
|
+
break;
|
|
1322
|
+
case 'bool':
|
|
1323
|
+
errorList.push({
|
|
1324
|
+
status: 400,
|
|
1325
|
+
code: code + '-MAP_13',
|
|
1326
|
+
description: this.createErrorMessage('MAP_33', [...keys, 0])
|
|
1327
|
+
});
|
|
1328
|
+
errorList.push({
|
|
1329
|
+
status: 400,
|
|
1330
|
+
code: code + '-MAP_14',
|
|
1331
|
+
description: this.createErrorMessage('MAP_34', [...keys, 0])
|
|
1332
|
+
});
|
|
1333
|
+
errorList.push({
|
|
1334
|
+
status: 400,
|
|
1335
|
+
code: code + '-MAP_15',
|
|
1336
|
+
description: this.createErrorMessage('MAP_35', [...keys, 0])
|
|
1337
|
+
});
|
|
1338
|
+
break;
|
|
1339
|
+
}
|
|
1340
|
+
break;
|
|
1341
|
+
default:
|
|
1342
|
+
errorList = [...errorList, ...this.getError([...keys, 0], code, false)];
|
|
1343
|
+
break;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
return errorList;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
private getError(keys: Array<string | number>, code: string, isRequestBody: boolean): Array<IError> {
|
|
1350
|
+
const errorList: Array<IError> = [];
|
|
1351
|
+
const property = this.getProperty(keys);
|
|
1352
|
+
switch (property.type) {
|
|
1353
|
+
case 'enum':
|
|
1354
|
+
case 'enum?':
|
|
1355
|
+
switch (property.enumType) {
|
|
1356
|
+
case 'number':
|
|
1357
|
+
case 'number?':
|
|
1358
|
+
errorList.push({
|
|
1359
|
+
status: 400,
|
|
1360
|
+
code: code + '-NUMBER_41',
|
|
1361
|
+
description: this.createErrorMessage('NUMBER_41', keys)
|
|
1362
|
+
});
|
|
1363
|
+
break;
|
|
1364
|
+
case 'string':
|
|
1365
|
+
case 'string?':
|
|
1366
|
+
errorList.push({
|
|
1367
|
+
status: 400,
|
|
1368
|
+
code: code + '-STRING_41',
|
|
1369
|
+
description: this.createErrorMessage('STRING_41', keys)
|
|
1370
|
+
});
|
|
1371
|
+
break;
|
|
1372
|
+
}
|
|
1373
|
+
errorList.push({
|
|
1374
|
+
status: 400,
|
|
1375
|
+
code: code + '-ENUM_42',
|
|
1376
|
+
description: this.createErrorMessage('ENUM_42', keys)
|
|
1377
|
+
});
|
|
1378
|
+
break;
|
|
1379
|
+
case 'number':
|
|
1380
|
+
case 'number?':
|
|
1381
|
+
errorList.push({
|
|
1382
|
+
status: 400,
|
|
1383
|
+
code: isRequestBody ? code + "-NUMBER_21" : code + "-NUMBER_91",
|
|
1384
|
+
description: this.createErrorMessage(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys)
|
|
1385
|
+
});
|
|
1386
|
+
|
|
1387
|
+
if (property.min !== undefined) {
|
|
1388
|
+
errorList.push({
|
|
1389
|
+
status: 400,
|
|
1390
|
+
code: isRequestBody ? code + "-NUMBER_22" : code + "-NUMBER_92",
|
|
1391
|
+
description: this.createErrorMessage(isRequestBody ? "NUMBER_22" : "NUMBER_92", keys)
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
if (property.max !== undefined) {
|
|
1396
|
+
errorList.push({
|
|
1397
|
+
status: 400,
|
|
1398
|
+
code: isRequestBody ? code + "-NUMBER_23" : code + "-NUMBER_93",
|
|
1399
|
+
description: this.createErrorMessage(isRequestBody ? "NUMBER_23" : "NUMBER_93", keys)
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
break;
|
|
1403
|
+
case 'boolean':
|
|
1404
|
+
case 'boolean?':
|
|
1405
|
+
errorList.push({
|
|
1406
|
+
status: 400,
|
|
1407
|
+
code: isRequestBody ? code + "-BOOL_21" : code + "-BOOL_91",
|
|
1408
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_21" : "BOOL_91", keys)
|
|
1409
|
+
});
|
|
1410
|
+
errorList.push({
|
|
1411
|
+
status: 400,
|
|
1412
|
+
code: isRequestBody ? code + "-BOOL_22" : code + "-BOOL_92",
|
|
1413
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_22" : "BOOL_92", keys)
|
|
1414
|
+
});
|
|
1415
|
+
errorList.push({
|
|
1416
|
+
status: 400,
|
|
1417
|
+
code: isRequestBody ? code + "-BOOL_23" : code + "-BOOL_93",
|
|
1418
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
|
|
1419
|
+
});
|
|
1420
|
+
break;
|
|
1421
|
+
case 'string':
|
|
1422
|
+
case 'string?':
|
|
1423
|
+
errorList.push({
|
|
1424
|
+
status: 400,
|
|
1425
|
+
code: isRequestBody ? code + "-STRING_21" : code + "-STRING_91",
|
|
1426
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
|
|
1427
|
+
});
|
|
1428
|
+
|
|
1429
|
+
if (property.maxLength !== undefined) {
|
|
1430
|
+
errorList.push({
|
|
1431
|
+
status: 400,
|
|
1432
|
+
code: isRequestBody ? code + "-STRING_22" : code + "-STRING_92",
|
|
1433
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1196
1436
|
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1437
|
+
if (property.regExp !== undefined) {
|
|
1438
|
+
errorList.push({
|
|
1439
|
+
status: 400,
|
|
1440
|
+
code: isRequestBody ? code + "-STRING_23" : code + "-STRING_93",
|
|
1441
|
+
description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
break;
|
|
1445
|
+
case 'uuid':
|
|
1446
|
+
case 'uuid?':
|
|
1447
|
+
errorList.push({
|
|
1448
|
+
status: 400,
|
|
1449
|
+
code: isRequestBody ? code + "-UUID_21" : code + "-UUID_91",
|
|
1450
|
+
description: this.createErrorMessage(isRequestBody ? "UUID_21" : "UUID_91", keys)
|
|
1451
|
+
});
|
|
1452
|
+
break;
|
|
1453
|
+
case 'mail':
|
|
1454
|
+
case 'mail?':
|
|
1455
|
+
errorList.push({
|
|
1456
|
+
status: 400,
|
|
1457
|
+
code: isRequestBody ? code + "-MAIL_21" : code + "-MAIL_91",
|
|
1458
|
+
description: this.createErrorMessage(isRequestBody ? "MAIL_21" : "MAIL_91", keys)
|
|
1459
|
+
});
|
|
1460
|
+
break;
|
|
1461
|
+
case 'date':
|
|
1462
|
+
case 'date?':
|
|
1463
|
+
errorList.push({
|
|
1464
|
+
status: 400,
|
|
1465
|
+
code: isRequestBody ? code + "-DATE_21" : code + "-DATE_91",
|
|
1466
|
+
description: this.createErrorMessage(isRequestBody ? "DATE_21" : "DATE_91", keys)
|
|
1467
|
+
});
|
|
1468
|
+
errorList.push({
|
|
1469
|
+
status: 400,
|
|
1470
|
+
code: isRequestBody ? code + "-DATE_22" : code + "-DATE_92",
|
|
1471
|
+
description: this.createErrorMessage(isRequestBody ? "DATE_22" : "DATE_92", keys)
|
|
1472
|
+
});
|
|
1473
|
+
break;
|
|
1474
|
+
case 'time':
|
|
1475
|
+
case 'time?':
|
|
1476
|
+
errorList.push({
|
|
1477
|
+
status: 400,
|
|
1478
|
+
code: isRequestBody ? code + "-TIME_21" : code + "-TIME_91",
|
|
1479
|
+
description: this.createErrorMessage(isRequestBody ? "TIME_21" : "TIME_91", keys)
|
|
1480
|
+
});
|
|
1481
|
+
break;
|
|
1482
|
+
case 'datetime':
|
|
1483
|
+
case 'datetime?':
|
|
1484
|
+
errorList.push({
|
|
1485
|
+
status: 400,
|
|
1486
|
+
code: isRequestBody ? code + "-DATETIME_21" : code + "-DATETIME_91",
|
|
1487
|
+
description: this.createErrorMessage(isRequestBody ? "DATETIME_21" : "DATETIME_91", keys)
|
|
1488
|
+
});
|
|
1489
|
+
errorList.push({
|
|
1490
|
+
status: 400,
|
|
1491
|
+
code: isRequestBody ? code + "-DATETIME_22" : code + "-DATETIME_92",
|
|
1492
|
+
description: this.createErrorMessage(isRequestBody ? "DATETIME_22" : "DATETIME_92", keys)
|
|
1493
|
+
});
|
|
1494
|
+
break;
|
|
1495
|
+
case 'https':
|
|
1496
|
+
case 'https?':
|
|
1497
|
+
errorList.push({
|
|
1498
|
+
status: 400,
|
|
1499
|
+
code: isRequestBody ? code + "-HTTPS_21" : code + "-HTTPS_91",
|
|
1500
|
+
description: this.createErrorMessage(isRequestBody ? "HTTPS_21" : "HTTPS_91", keys)
|
|
1501
|
+
});
|
|
1502
|
+
break;
|
|
1503
|
+
case 'base64':
|
|
1504
|
+
case 'base64?':
|
|
1505
|
+
errorList.push({
|
|
1506
|
+
status: 400,
|
|
1507
|
+
code: isRequestBody ? code + "-BASE64_21" : code + "-BASE64_91",
|
|
1508
|
+
description: this.createErrorMessage(isRequestBody ? "BASE64_21" : "BASE64_91", keys)
|
|
1509
|
+
});
|
|
1510
|
+
break;
|
|
1207
1511
|
}
|
|
1208
1512
|
|
|
1209
1513
|
return errorList;
|
|
@@ -435,11 +435,11 @@ export class ResponseType extends ReqResType {
|
|
|
435
435
|
if (list.length === 1) {
|
|
436
436
|
// 単一エラーは1行説明
|
|
437
437
|
ymlString += ` '${status}':
|
|
438
|
-
description: ${list[0].code
|
|
438
|
+
description: ${list[0].description}${list[0].code !== '' ? ` [${list[0].code}]` : ''}
|
|
439
439
|
`;
|
|
440
440
|
} else {
|
|
441
441
|
// 複数エラーは箇条書き
|
|
442
|
-
const bullets = list.map(e => `- ${e.code !== '' ?
|
|
442
|
+
const bullets = list.map(e => `- ${e.description}${e.code !== '' ? ` [${e.code}]` : ''}`).join(descIndentJoin);
|
|
443
443
|
ymlString += ` '${status}':
|
|
444
444
|
description: |${descIndentJoin}${bullets}
|
|
445
445
|
`;
|