pg-mvc-service 2.0.114 → 2.0.115

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 ? "NUMBER_21" : "NUMBER_91", keys, value);
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 ? "NUMBER_21" : "NUMBER_91", keys, value);
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
- const errorList = [];
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
+ // TODO: obj
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
+ // TODO: Arr
1051
1053
  break;
1052
1054
  case 'map':
1053
1055
  case 'map?':
@@ -1085,22 +1087,171 @@ class RequestType extends ReqResType_1.default {
1085
1087
  break;
1086
1088
  }
1087
1089
  break;
1088
- case 'enum':
1089
- case 'enum?':
1090
- break;
1091
1090
  default:
1091
+ errorList = [...errorList, ...this.getError([key], code, true)];
1092
1092
  break;
1093
1093
  }
1094
- // this.changeBody([key], mapData);
1095
- // break;
1096
- // case 'enum':
1097
- // case 'enum?':
1098
- // this.setEnum([key], value);
1099
- // break;
1100
- // default:
1101
- // this.convertInput([key], value);
1102
- // break;
1103
- // }
1094
+ }
1095
+ return errorList;
1096
+ }
1097
+ getError(keys, code, isRequestBody) {
1098
+ const errorList = [];
1099
+ const property = this.getProperty(keys);
1100
+ switch (property.type) {
1101
+ case 'enum':
1102
+ case 'enum?':
1103
+ switch (property.enumType) {
1104
+ case 'number':
1105
+ case 'number?':
1106
+ errorList.push({
1107
+ status: 400,
1108
+ code: code + '-NUMBER_41',
1109
+ description: this.createErrorMessage('NUMBER_41', keys)
1110
+ });
1111
+ break;
1112
+ case 'string':
1113
+ case 'string?':
1114
+ errorList.push({
1115
+ status: 400,
1116
+ code: code + '-STRING_41',
1117
+ description: this.createErrorMessage('STRING_41', keys)
1118
+ });
1119
+ break;
1120
+ }
1121
+ errorList.push({
1122
+ status: 400,
1123
+ code: code + '-ENUM_42',
1124
+ description: this.createErrorMessage('ENUM_42', keys)
1125
+ });
1126
+ break;
1127
+ case 'number':
1128
+ case 'number?':
1129
+ errorList.push({
1130
+ status: 400,
1131
+ code: isRequestBody ? code + "-NUMBER_21" : code + "-NUMBER_91",
1132
+ description: this.createErrorMessage(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys)
1133
+ });
1134
+ if (property.min !== undefined) {
1135
+ errorList.push({
1136
+ status: 400,
1137
+ code: isRequestBody ? code + "-NUMBER_22" : code + "-NUMBER_92",
1138
+ description: this.createErrorMessage(isRequestBody ? "NUMBER_22" : "NUMBER_92", keys)
1139
+ });
1140
+ }
1141
+ if (property.max !== undefined) {
1142
+ errorList.push({
1143
+ status: 400,
1144
+ code: isRequestBody ? code + "-NUMBER_23" : code + "-NUMBER_93",
1145
+ description: this.createErrorMessage(isRequestBody ? "NUMBER_23" : "NUMBER_93", keys)
1146
+ });
1147
+ }
1148
+ break;
1149
+ case 'boolean':
1150
+ case 'boolean?':
1151
+ errorList.push({
1152
+ status: 400,
1153
+ code: isRequestBody ? code + "-BOOL_21" : code + "-BOOL_91",
1154
+ description: this.createErrorMessage(isRequestBody ? "BOOL_21" : "BOOL_91", keys)
1155
+ });
1156
+ errorList.push({
1157
+ status: 400,
1158
+ code: isRequestBody ? code + "-BOOL_22" : code + "-BOOL_92",
1159
+ description: this.createErrorMessage(isRequestBody ? "BOOL_22" : "BOOL_92", keys)
1160
+ });
1161
+ errorList.push({
1162
+ status: 400,
1163
+ code: isRequestBody ? code + "-BOOL_23" : code + "-BOOL_93",
1164
+ description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
1165
+ });
1166
+ break;
1167
+ case 'string':
1168
+ case 'string?':
1169
+ errorList.push({
1170
+ status: 400,
1171
+ code: isRequestBody ? code + "-STRING_21" : code + "-STRING_91",
1172
+ description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
1173
+ });
1174
+ if (property.maxLength !== undefined) {
1175
+ errorList.push({
1176
+ status: 400,
1177
+ code: isRequestBody ? code + "-STRING_22" : code + "-STRING_92",
1178
+ description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
1179
+ });
1180
+ }
1181
+ if (property.regExp !== undefined) {
1182
+ errorList.push({
1183
+ status: 400,
1184
+ code: isRequestBody ? code + "-STRING_23" : code + "-STRING_93",
1185
+ description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
1186
+ });
1187
+ }
1188
+ break;
1189
+ case 'uuid':
1190
+ case 'uuid?':
1191
+ errorList.push({
1192
+ status: 400,
1193
+ code: isRequestBody ? code + "-UUID_21" : code + "-UUID_91",
1194
+ description: this.createErrorMessage(isRequestBody ? "UUID_21" : "UUID_91", keys)
1195
+ });
1196
+ break;
1197
+ case 'mail':
1198
+ case 'mail?':
1199
+ errorList.push({
1200
+ status: 400,
1201
+ code: isRequestBody ? code + "-MAIL_21" : code + "-MAIL_91",
1202
+ description: this.createErrorMessage(isRequestBody ? "MAIL_21" : "MAIL_91", keys)
1203
+ });
1204
+ break;
1205
+ case 'date':
1206
+ case 'date?':
1207
+ errorList.push({
1208
+ status: 400,
1209
+ code: isRequestBody ? code + "-DATE_21" : code + "-DATE_91",
1210
+ description: this.createErrorMessage(isRequestBody ? "DATE_21" : "DATE_91", keys)
1211
+ });
1212
+ errorList.push({
1213
+ status: 400,
1214
+ code: isRequestBody ? code + "-DATE_22" : code + "-DATE_92",
1215
+ description: this.createErrorMessage(isRequestBody ? "DATE_22" : "DATE_92", keys)
1216
+ });
1217
+ break;
1218
+ case 'time':
1219
+ case 'time?':
1220
+ errorList.push({
1221
+ status: 400,
1222
+ code: isRequestBody ? code + "-TIME_21" : code + "-TIME_91",
1223
+ description: this.createErrorMessage(isRequestBody ? "TIME_21" : "TIME_91", keys)
1224
+ });
1225
+ break;
1226
+ case 'datetime':
1227
+ case 'datetime?':
1228
+ errorList.push({
1229
+ status: 400,
1230
+ code: isRequestBody ? code + "-DATETIME_21" : code + "-DATETIME_91",
1231
+ description: this.createErrorMessage(isRequestBody ? "DATETIME_21" : "DATETIME_91", keys)
1232
+ });
1233
+ errorList.push({
1234
+ status: 400,
1235
+ code: isRequestBody ? code + "-DATETIME_22" : code + "-DATETIME_92",
1236
+ description: this.createErrorMessage(isRequestBody ? "DATETIME_22" : "DATETIME_92", keys)
1237
+ });
1238
+ break;
1239
+ case 'https':
1240
+ case 'https?':
1241
+ errorList.push({
1242
+ status: 400,
1243
+ code: isRequestBody ? code + "-HTTPS_21" : code + "-HTTPS_91",
1244
+ description: this.createErrorMessage(isRequestBody ? "HTTPS_21" : "HTTPS_91", keys)
1245
+ });
1246
+ break;
1247
+ case 'base64':
1248
+ case 'base64?':
1249
+ errorList.push({
1250
+ status: 400,
1251
+ code: isRequestBody ? code + "-BASE64_21" : code + "-BASE64_91",
1252
+ description: this.createErrorMessage(isRequestBody ? "BASE64_21" : "BASE64_91", keys)
1253
+ });
1254
+ break;
1104
1255
  }
1105
1256
  return errorList;
1106
1257
  }
@@ -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}: ${list[0].description}
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 !== '' ? `${e.code}: ` : ''}${e.description}`).join(descIndentJoin);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.114",
3
+ "version": "2.0.115",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -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 ? "NUMBER_21" : "NUMBER_91", keys, value);
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 ? "NUMBER_21" : "NUMBER_91", keys, value);
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
- const errorList: Array<IError> = [];
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,7 @@ export class RequestType extends ReqResType {
1142
1142
  code: code + '-OBJECT_01',
1143
1143
  description: this.createErrorMessage('OBJECT_01', [key])
1144
1144
  });
1145
+ // TODO: obj
1145
1146
  break;
1146
1147
  case 'array':
1147
1148
  case 'array?':
@@ -1150,6 +1151,7 @@ export class RequestType extends ReqResType {
1150
1151
  code: code + '-ARRAY_01',
1151
1152
  description: this.createErrorMessage('ARRAY_01', [key])
1152
1153
  });
1154
+ // TODO: Arr
1153
1155
  break;
1154
1156
  case 'map':
1155
1157
  case 'map?':
@@ -1187,23 +1189,177 @@ export class RequestType extends ReqResType {
1187
1189
  break;
1188
1190
  }
1189
1191
  break;
1190
- case 'enum':
1191
- case 'enum?':
1192
- break;
1193
1192
  default:
1193
+ errorList = [...errorList, ...this.getError([key], code, true)];
1194
1194
  break;
1195
1195
  }
1196
+ }
1197
+
1198
+ return errorList;
1199
+ }
1200
+
1201
+ private getError(keys: Array<string | number>, code: string, isRequestBody: boolean) {
1202
+ const errorList: Array<IError> = [];
1203
+ const property = this.getProperty(keys);
1204
+ switch (property.type) {
1205
+ case 'enum':
1206
+ case 'enum?':
1207
+ switch (property.enumType) {
1208
+ case 'number':
1209
+ case 'number?':
1210
+ errorList.push({
1211
+ status: 400,
1212
+ code: code + '-NUMBER_41',
1213
+ description: this.createErrorMessage('NUMBER_41', keys)
1214
+ });
1215
+ break;
1216
+ case 'string':
1217
+ case 'string?':
1218
+ errorList.push({
1219
+ status: 400,
1220
+ code: code + '-STRING_41',
1221
+ description: this.createErrorMessage('STRING_41', keys)
1222
+ });
1223
+ break;
1224
+ }
1225
+ errorList.push({
1226
+ status: 400,
1227
+ code: code + '-ENUM_42',
1228
+ description: this.createErrorMessage('ENUM_42', keys)
1229
+ });
1230
+ break;
1231
+ case 'number':
1232
+ case 'number?':
1233
+ errorList.push({
1234
+ status: 400,
1235
+ code: isRequestBody ? code + "-NUMBER_21" : code + "-NUMBER_91",
1236
+ description: this.createErrorMessage(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys)
1237
+ });
1238
+
1239
+ if (property.min !== undefined) {
1240
+ errorList.push({
1241
+ status: 400,
1242
+ code: isRequestBody ? code + "-NUMBER_22" : code + "-NUMBER_92",
1243
+ description: this.createErrorMessage(isRequestBody ? "NUMBER_22" : "NUMBER_92", keys)
1244
+ });
1245
+ }
1246
+
1247
+ if (property.max !== undefined) {
1248
+ errorList.push({
1249
+ status: 400,
1250
+ code: isRequestBody ? code + "-NUMBER_23" : code + "-NUMBER_93",
1251
+ description: this.createErrorMessage(isRequestBody ? "NUMBER_23" : "NUMBER_93", keys)
1252
+ });
1253
+ }
1254
+ break;
1255
+ case 'boolean':
1256
+ case 'boolean?':
1257
+ errorList.push({
1258
+ status: 400,
1259
+ code: isRequestBody ? code + "-BOOL_21" : code + "-BOOL_91",
1260
+ description: this.createErrorMessage(isRequestBody ? "BOOL_21" : "BOOL_91", keys)
1261
+ });
1262
+ errorList.push({
1263
+ status: 400,
1264
+ code: isRequestBody ? code + "-BOOL_22" : code + "-BOOL_92",
1265
+ description: this.createErrorMessage(isRequestBody ? "BOOL_22" : "BOOL_92", keys)
1266
+ });
1267
+ errorList.push({
1268
+ status: 400,
1269
+ code: isRequestBody ? code + "-BOOL_23" : code + "-BOOL_93",
1270
+ description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
1271
+ });
1272
+ break;
1273
+ case 'string':
1274
+ case 'string?':
1275
+ errorList.push({
1276
+ status: 400,
1277
+ code: isRequestBody ? code + "-STRING_21" : code + "-STRING_91",
1278
+ description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
1279
+ });
1196
1280
 
1197
- // this.changeBody([key], mapData);
1198
- // break;
1199
- // case 'enum':
1200
- // case 'enum?':
1201
- // this.setEnum([key], value);
1202
- // break;
1203
- // default:
1204
- // this.convertInput([key], value);
1205
- // break;
1206
- // }
1281
+ if (property.maxLength !== undefined) {
1282
+ errorList.push({
1283
+ status: 400,
1284
+ code: isRequestBody ? code + "-STRING_22" : code + "-STRING_92",
1285
+ description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
1286
+ });
1287
+ }
1288
+
1289
+ if (property.regExp !== undefined) {
1290
+ errorList.push({
1291
+ status: 400,
1292
+ code: isRequestBody ? code + "-STRING_23" : code + "-STRING_93",
1293
+ description: this.createErrorMessage(isRequestBody ? "BOOL_23" : "BOOL_93", keys)
1294
+ });
1295
+ }
1296
+ break;
1297
+ case 'uuid':
1298
+ case 'uuid?':
1299
+ errorList.push({
1300
+ status: 400,
1301
+ code: isRequestBody ? code + "-UUID_21" : code + "-UUID_91",
1302
+ description: this.createErrorMessage(isRequestBody ? "UUID_21" : "UUID_91", keys)
1303
+ });
1304
+ break;
1305
+ case 'mail':
1306
+ case 'mail?':
1307
+ errorList.push({
1308
+ status: 400,
1309
+ code: isRequestBody ? code + "-MAIL_21" : code + "-MAIL_91",
1310
+ description: this.createErrorMessage(isRequestBody ? "MAIL_21" : "MAIL_91", keys)
1311
+ });
1312
+ break;
1313
+ case 'date':
1314
+ case 'date?':
1315
+ errorList.push({
1316
+ status: 400,
1317
+ code: isRequestBody ? code + "-DATE_21" : code + "-DATE_91",
1318
+ description: this.createErrorMessage(isRequestBody ? "DATE_21" : "DATE_91", keys)
1319
+ });
1320
+ errorList.push({
1321
+ status: 400,
1322
+ code: isRequestBody ? code + "-DATE_22" : code + "-DATE_92",
1323
+ description: this.createErrorMessage(isRequestBody ? "DATE_22" : "DATE_92", keys)
1324
+ });
1325
+ break;
1326
+ case 'time':
1327
+ case 'time?':
1328
+ errorList.push({
1329
+ status: 400,
1330
+ code: isRequestBody ? code + "-TIME_21" : code + "-TIME_91",
1331
+ description: this.createErrorMessage(isRequestBody ? "TIME_21" : "TIME_91", keys)
1332
+ });
1333
+ break;
1334
+ case 'datetime':
1335
+ case 'datetime?':
1336
+ errorList.push({
1337
+ status: 400,
1338
+ code: isRequestBody ? code + "-DATETIME_21" : code + "-DATETIME_91",
1339
+ description: this.createErrorMessage(isRequestBody ? "DATETIME_21" : "DATETIME_91", keys)
1340
+ });
1341
+ errorList.push({
1342
+ status: 400,
1343
+ code: isRequestBody ? code + "-DATETIME_22" : code + "-DATETIME_92",
1344
+ description: this.createErrorMessage(isRequestBody ? "DATETIME_22" : "DATETIME_92", keys)
1345
+ });
1346
+ break;
1347
+ case 'https':
1348
+ case 'https?':
1349
+ errorList.push({
1350
+ status: 400,
1351
+ code: isRequestBody ? code + "-HTTPS_21" : code + "-HTTPS_91",
1352
+ description: this.createErrorMessage(isRequestBody ? "HTTPS_21" : "HTTPS_91", keys)
1353
+ });
1354
+ break;
1355
+ case 'base64':
1356
+ case 'base64?':
1357
+ errorList.push({
1358
+ status: 400,
1359
+ code: isRequestBody ? code + "-BASE64_21" : code + "-BASE64_91",
1360
+ description: this.createErrorMessage(isRequestBody ? "BASE64_21" : "BASE64_91", keys)
1361
+ });
1362
+ break;
1207
1363
  }
1208
1364
 
1209
1365
  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}: ${list[0].description}
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 !== '' ? `${e.code}: ` : ''}${e.description}`).join(descIndentJoin);
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
  `;