pg-mvc-service 2.0.113 → 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.
@@ -118,15 +118,7 @@ class RequestType extends ReqResType_1.default {
118
118
  this.headers = (_b = request.headers) !== null && _b !== void 0 ? _b : {};
119
119
  this.remoteAddress = (_c = request.socket) === null || _c === void 0 ? void 0 : _c.remoteAddress;
120
120
  }
121
- /**
122
- * Generates an error message based on the provided code, keys, and value.
123
- * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
124
- * @param {string} code - The error code. エラーコード
125
- * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
126
- * @param {any} value - The value that caused the error. エラーを引き起こした値
127
- * @returns {string} The generated error message. 生成されたエラーメッセージ
128
- */
129
- throwInputError(code, keys, value) {
121
+ createErrorMessage(code, keys, value) {
130
122
  var _a, _b, _c, _d, _e;
131
123
  const list = {
132
124
  "REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
@@ -214,8 +206,25 @@ class RequestType extends ReqResType_1.default {
214
206
  errorMessage = errorMessage.replace('{min}', ((_e = property.min) !== null && _e !== void 0 ? _e : '[未指定]').toString());
215
207
  break;
216
208
  }
217
- errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
218
- throw new Exception_1.InputErrorException(code, errorMessage);
209
+ errorMessage = errorMessage.replace("{property}", keys.join('.'));
210
+ if (value === undefined) {
211
+ errorMessage = errorMessage.replace("{value}", value);
212
+ }
213
+ else {
214
+ errorMessage = errorMessage.replace("{value}", "");
215
+ }
216
+ return errorMessage;
217
+ }
218
+ /**
219
+ * Generates an error message based on the provided code, keys, and value.
220
+ * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
221
+ * @param {string} code - The error code. エラーコード
222
+ * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
223
+ * @param {any} value - The value that caused the error. エラーを引き起こした値
224
+ * @returns {string} The generated error message. 生成されたエラーメッセージ
225
+ */
226
+ throwInputError(code, keys, value) {
227
+ throw new Exception_1.InputErrorException(code, this.createErrorMessage(code, keys, value));
219
228
  }
220
229
  /**
221
230
  * Sets the values of the request body to the class properties.
@@ -713,10 +722,10 @@ class RequestType extends ReqResType_1.default {
713
722
  }
714
723
  const numberValue = Number(value);
715
724
  if (property.min !== undefined && numberValue < property.min) {
716
- this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
725
+ this.throwInputError(isRequestBody ? "NUMBER_22" : "NUMBER_92", keys, value);
717
726
  }
718
727
  if (property.max !== undefined && numberValue > property.max) {
719
- this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
728
+ this.throwInputError(isRequestBody ? "NUMBER_23" : "NUMBER_93", keys, value);
720
729
  }
721
730
  return numberValue;
722
731
  case 'boolean':
@@ -1013,14 +1022,14 @@ class RequestType extends ReqResType_1.default {
1013
1022
  return ymlString;
1014
1023
  }
1015
1024
  getInputErrorList(method, code) {
1016
- const errorList = [];
1025
+ let errorList = [];
1017
1026
  for (const [key, property] of Object.entries(this.properties)) {
1018
1027
  if (property.type.endsWith('?') === false) {
1019
1028
  const errorCode = property.type === 'array' && ['GET', 'DELETE'].includes(method) ? 'REQUIRE_00' : 'REQUIRE_01';
1020
1029
  errorList.push({
1021
1030
  status: 400,
1022
1031
  code: code + '-' + errorCode,
1023
- description: this.throwInputError(errorCode, [key], "")
1032
+ description: this.createErrorMessage(errorCode, [key])
1024
1033
  });
1025
1034
  }
1026
1035
  switch (property.type) {
@@ -1029,16 +1038,18 @@ class RequestType extends ReqResType_1.default {
1029
1038
  errorList.push({
1030
1039
  status: 400,
1031
1040
  code: code + '-OBJECT_01',
1032
- description: this.throwInputError('OBJECT_01', [key], "")
1041
+ description: this.createErrorMessage('OBJECT_01', [key])
1033
1042
  });
1043
+ // TODO: obj
1034
1044
  break;
1035
1045
  case 'array':
1036
1046
  case 'array?':
1037
1047
  errorList.push({
1038
1048
  status: 400,
1039
1049
  code: code + '-ARRAY_01',
1040
- description: this.throwInputError('ARRAY_01', [key], "")
1050
+ description: this.createErrorMessage('ARRAY_01', [key])
1041
1051
  });
1052
+ // TODO: Arr
1042
1053
  break;
1043
1054
  case 'map':
1044
1055
  case 'map?':
@@ -1047,51 +1058,200 @@ class RequestType extends ReqResType_1.default {
1047
1058
  errorList.push({
1048
1059
  status: 400,
1049
1060
  code: code + '-MAP_01',
1050
- description: this.throwInputError('MAP_01', [key], "")
1061
+ description: this.createErrorMessage('MAP_01', [key])
1051
1062
  });
1052
1063
  break;
1053
1064
  case 'string':
1054
1065
  errorList.push({
1055
1066
  status: 400,
1056
1067
  code: code + '-MAP_02',
1057
- description: this.throwInputError('MAP_02', [key], "")
1068
+ description: this.createErrorMessage('MAP_02', [key])
1058
1069
  });
1059
1070
  break;
1060
1071
  case 'bool':
1061
1072
  errorList.push({
1062
1073
  status: 400,
1063
1074
  code: code + '-MAP_03',
1064
- description: this.throwInputError('MAP_03', [key], "")
1075
+ description: this.createErrorMessage('MAP_03', [key])
1065
1076
  });
1066
1077
  errorList.push({
1067
1078
  status: 400,
1068
1079
  code: code + '-MAP_04',
1069
- description: this.throwInputError('MAP_04', [key], "")
1080
+ description: this.createErrorMessage('MAP_04', [key])
1070
1081
  });
1071
1082
  errorList.push({
1072
1083
  status: 400,
1073
1084
  code: code + '-MAP_05',
1074
- description: this.throwInputError('MAP_05', [key], "")
1085
+ description: this.createErrorMessage('MAP_05', [key])
1075
1086
  });
1076
1087
  break;
1077
1088
  }
1078
1089
  break;
1079
- case 'enum':
1080
- case 'enum?':
1081
- break;
1082
1090
  default:
1091
+ errorList = [...errorList, ...this.getError([key], code, true)];
1083
1092
  break;
1084
1093
  }
1085
- // this.changeBody([key], mapData);
1086
- // break;
1087
- // case 'enum':
1088
- // case 'enum?':
1089
- // this.setEnum([key], value);
1090
- // break;
1091
- // default:
1092
- // this.convertInput([key], value);
1093
- // break;
1094
- // }
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;
1095
1255
  }
1096
1256
  return errorList;
1097
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.113",
3
+ "version": "2.0.115",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -145,15 +145,7 @@ export class RequestType extends ReqResType {
145
145
  this.remoteAddress = request.socket?.remoteAddress;
146
146
  }
147
147
 
148
- /**
149
- * Generates an error message based on the provided code, keys, and value.
150
- * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
151
- * @param {string} code - The error code. エラーコード
152
- * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
153
- * @param {any} value - The value that caused the error. エラーを引き起こした値
154
- * @returns {string} The generated error message. 生成されたエラーメッセージ
155
- */
156
- private throwInputError(code:
148
+ private createErrorMessage(code:
157
149
  "REQUIRE_00" | "REQUIRE_01" | "OBJECT_01" | "ARRAY_01" | "UNNECESSARY_01" |
158
150
  "REQUIRE_11" | "OBJECT_11" | "ARRAY_11" | "UNNECESSARY_11" |
159
151
  "NUMBER_21" | "NUMBER_22" | "NUMBER_23" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "STRING_22" | "STRING_23" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
@@ -163,8 +155,10 @@ export class RequestType extends ReqResType {
163
155
  "MAP_01" | "MAP_02" | "MAP_03" | "MAP_04" | "MAP_05" | "MAP_11" | "MAP_12" | "MAP_13" | "MAP_14" | "MAP_15" |
164
156
  "MAP_31" | "MAP_32" | "MAP_33" | "MAP_34" | "MAP_35" |
165
157
  "NUMBER_91" | "NUMBER_92" | "NUMBER_93" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "STRING_92" | "STRING_93" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
166
- "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
167
- , keys: Array<string | number>, value: any): never {
158
+ "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91",
159
+ keys: Array<string | number>,
160
+ value?: any
161
+ ) {
168
162
  const list = {
169
163
  "REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
170
164
  "REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
@@ -253,9 +247,38 @@ export class RequestType extends ReqResType {
253
247
  break;
254
248
  }
255
249
 
256
- errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
250
+ errorMessage = errorMessage.replace("{property}", keys.join('.'));
251
+ if (value === undefined) {
252
+ errorMessage = errorMessage.replace("{value}", value);
253
+ } else {
254
+ errorMessage = errorMessage.replace("{value}", "");
255
+ }
256
+
257
+ return errorMessage;
258
+ }
259
+
260
+ /**
261
+ * Generates an error message based on the provided code, keys, and value.
262
+ * 指定されたコード、キー、および値に基づいてエラーメッセージを生成します。
263
+ * @param {string} code - The error code. エラーコード
264
+ * @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
265
+ * @param {any} value - The value that caused the error. エラーを引き起こした値
266
+ * @returns {string} The generated error message. 生成されたエラーメッセージ
267
+ */
268
+ private throwInputError(code:
269
+ "REQUIRE_00" | "REQUIRE_01" | "OBJECT_01" | "ARRAY_01" | "UNNECESSARY_01" |
270
+ "REQUIRE_11" | "OBJECT_11" | "ARRAY_11" | "UNNECESSARY_11" |
271
+ "NUMBER_21" | "NUMBER_22" | "NUMBER_23" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "STRING_22" | "STRING_23" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
272
+ "TIME_21" | "DATETIME_21" | "DATETIME_22" | "HTTPS_21" | "BASE64_21" |
273
+ "REQUIRE_31" |
274
+ "ENUM_32" | "ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
275
+ "MAP_01" | "MAP_02" | "MAP_03" | "MAP_04" | "MAP_05" | "MAP_11" | "MAP_12" | "MAP_13" | "MAP_14" | "MAP_15" |
276
+ "MAP_31" | "MAP_32" | "MAP_33" | "MAP_34" | "MAP_35" |
277
+ "NUMBER_91" | "NUMBER_92" | "NUMBER_93" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "STRING_92" | "STRING_93" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
278
+ "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
279
+ , keys: Array<string | number>, value: any): never {
257
280
 
258
- throw new InputErrorException(code, errorMessage);
281
+ throw new InputErrorException(code, this.createErrorMessage(code, keys, value));
259
282
  }
260
283
 
261
284
  /**
@@ -766,11 +789,11 @@ export class RequestType extends ReqResType {
766
789
  }
767
790
  const numberValue = Number(value);
768
791
  if (property.min !== undefined && numberValue < property.min) {
769
- this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
792
+ this.throwInputError(isRequestBody ? "NUMBER_22" : "NUMBER_92", keys, value);
770
793
  }
771
794
 
772
795
  if (property.max !== undefined && numberValue > property.max) {
773
- this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
796
+ this.throwInputError(isRequestBody ? "NUMBER_23" : "NUMBER_93", keys, value);
774
797
  }
775
798
  return numberValue;
776
799
  case 'boolean':
@@ -1100,14 +1123,14 @@ export class RequestType extends ReqResType {
1100
1123
  }
1101
1124
 
1102
1125
  public getInputErrorList(method: string, code: string): Array<IError> {
1103
- const errorList: Array<IError> = [];
1126
+ let errorList: Array<IError> = [];
1104
1127
  for (const [key, property] of Object.entries(this.properties)) {
1105
1128
  if (property.type.endsWith('?') === false) {
1106
1129
  const errorCode = property.type === 'array' && ['GET', 'DELETE'].includes(method) ? 'REQUIRE_00' : 'REQUIRE_01';
1107
1130
  errorList.push({
1108
1131
  status: 400,
1109
1132
  code: code + '-' + errorCode,
1110
- description: this.throwInputError(errorCode, [key], "")
1133
+ description: this.createErrorMessage(errorCode, [key])
1111
1134
  });
1112
1135
  }
1113
1136
 
@@ -1117,16 +1140,18 @@ export class RequestType extends ReqResType {
1117
1140
  errorList.push({
1118
1141
  status: 400,
1119
1142
  code: code + '-OBJECT_01',
1120
- description: this.throwInputError('OBJECT_01', [key], "")
1143
+ description: this.createErrorMessage('OBJECT_01', [key])
1121
1144
  });
1145
+ // TODO: obj
1122
1146
  break;
1123
1147
  case 'array':
1124
1148
  case 'array?':
1125
1149
  errorList.push({
1126
1150
  status: 400,
1127
1151
  code: code + '-ARRAY_01',
1128
- description: this.throwInputError('ARRAY_01', [key], "")
1152
+ description: this.createErrorMessage('ARRAY_01', [key])
1129
1153
  });
1154
+ // TODO: Arr
1130
1155
  break;
1131
1156
  case 'map':
1132
1157
  case 'map?':
@@ -1135,52 +1160,206 @@ export class RequestType extends ReqResType {
1135
1160
  errorList.push({
1136
1161
  status: 400,
1137
1162
  code: code + '-MAP_01',
1138
- description: this.throwInputError('MAP_01', [key], "")
1163
+ description: this.createErrorMessage('MAP_01', [key])
1139
1164
  });
1140
1165
  break;
1141
1166
  case 'string':
1142
1167
  errorList.push({
1143
1168
  status: 400,
1144
1169
  code: code + '-MAP_02',
1145
- description: this.throwInputError('MAP_02', [key], "")
1170
+ description: this.createErrorMessage('MAP_02', [key])
1146
1171
  });
1147
1172
  break;
1148
1173
  case 'bool':
1149
1174
  errorList.push({
1150
1175
  status: 400,
1151
1176
  code: code + '-MAP_03',
1152
- description: this.throwInputError('MAP_03', [key], "")
1177
+ description: this.createErrorMessage('MAP_03', [key])
1153
1178
  });
1154
1179
  errorList.push({
1155
1180
  status: 400,
1156
1181
  code: code + '-MAP_04',
1157
- description: this.throwInputError('MAP_04', [key], "")
1182
+ description: this.createErrorMessage('MAP_04', [key])
1158
1183
  });
1159
1184
  errorList.push({
1160
1185
  status: 400,
1161
1186
  code: code + '-MAP_05',
1162
- description: this.throwInputError('MAP_05', [key], "")
1187
+ description: this.createErrorMessage('MAP_05', [key])
1163
1188
  });
1164
1189
  break;
1165
1190
  }
1166
1191
  break;
1167
- case 'enum':
1168
- case 'enum?':
1169
- break;
1170
1192
  default:
1193
+ errorList = [...errorList, ...this.getError([key], code, true)];
1171
1194
  break;
1172
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
+ });
1173
1238
 
1174
- // this.changeBody([key], mapData);
1175
- // break;
1176
- // case 'enum':
1177
- // case 'enum?':
1178
- // this.setEnum([key], value);
1179
- // break;
1180
- // default:
1181
- // this.convertInput([key], value);
1182
- // break;
1183
- // }
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
+ });
1280
+
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;
1184
1363
  }
1185
1364
 
1186
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
  `;