pg-mvc-service 1.0.13 → 1.0.15
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.
- package/dist/Service.js +1 -1
- package/dist/reqestResponse/RequestType.js +104 -91
- package/index.d.ts +3 -17
- package/package.json +1 -1
- package/src/Service.ts +1 -1
- package/src/reqestResponse/ReqResType.ts +0 -1
- package/src/reqestResponse/RequestType.ts +142 -100
package/dist/Service.js
CHANGED
|
@@ -24,7 +24,7 @@ const EncryptClient_1 = require("./clients/EncryptClient");
|
|
|
24
24
|
const PoolManager_1 = __importDefault(require("./PoolManager"));
|
|
25
25
|
class Service {
|
|
26
26
|
get Method() { return this.method; }
|
|
27
|
-
get Endpoint() { return this.endpoint; }
|
|
27
|
+
get Endpoint() { return this.endpoint + this.request.paramPath; }
|
|
28
28
|
get ApiCode() { return this.apiCode; }
|
|
29
29
|
get Summary() { return `${this.ApiCode !== '' ? this.apiCode + ': ' : ''}${this.summary}`; }
|
|
30
30
|
get ApiUserAvailable() { return this.apiUserAvailable; }
|
|
@@ -33,24 +33,27 @@ class RequestType extends ReqResType_1.default {
|
|
|
33
33
|
INVALID_ENUM: '{property} must be in {enums}. ({value})'
|
|
34
34
|
};
|
|
35
35
|
this.ERROR_MESSAGE_JAPAN = {
|
|
36
|
-
BODY_REQUIRED: 'リクエストボディが必要です。',
|
|
37
36
|
REQUIRED: '{property}は必須項目です。',
|
|
38
37
|
UNNECESSARY: '{property}は不要な入力です。',
|
|
39
|
-
INVALID_OBJECT: '{property}
|
|
40
|
-
INVALID_ARRAY: '{property}
|
|
41
|
-
INVALID_NUMBER: '{property}
|
|
42
|
-
INVALID_BOOL: '{property}
|
|
43
|
-
INVALID_STRING: '{property}
|
|
44
|
-
INVALID_UUID: '{property}はUUID
|
|
45
|
-
INVALID_MAIL: '{property}
|
|
46
|
-
INVALID_HTTPS: '{property}はhttpsまたはhttpのURL
|
|
47
|
-
INVALID_DATE: '{property}は"YYYY-MM-DD"
|
|
48
|
-
INVALID_TIME: '{property}は"hh:mi"
|
|
49
|
-
INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"
|
|
50
|
-
INVALID_BASE64: '{property}はBase64
|
|
51
|
-
INVALID_ENUM: '{property}は{enums}
|
|
38
|
+
INVALID_OBJECT: '{property}はobject型で入力してください。({value})',
|
|
39
|
+
INVALID_ARRAY: '{property}はarray型で入力してください。({value})',
|
|
40
|
+
INVALID_NUMBER: '{property}はnumber型または半角数値のstring型で入力してください。({value})',
|
|
41
|
+
INVALID_BOOL: '{property}はboolean型またはtrue、falseのstring型または0、1のnumber型で入力してください。({value})',
|
|
42
|
+
INVALID_STRING: '{property}はstring型で入力してください。({value})',
|
|
43
|
+
INVALID_UUID: '{property}はUUID形式のstring型で入力してください。({value})',
|
|
44
|
+
INVALID_MAIL: '{property}はメールアドレス形式のstring型で入力してください。({value})',
|
|
45
|
+
INVALID_HTTPS: '{property}はhttpsまたはhttpのURL形式のstring型で入力してください。({value})',
|
|
46
|
+
INVALID_DATE: '{property}は"YYYY-MM-DD"形式のstring型で入力してください。({value})',
|
|
47
|
+
INVALID_TIME: '{property}は"hh:mi"形式のstring型で入力してください。({value})',
|
|
48
|
+
INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式のstring型で入力してください。({value})',
|
|
49
|
+
INVALID_BASE64: '{property}はBase64形式のstring型で入力してください。({value})',
|
|
50
|
+
INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})'
|
|
52
51
|
};
|
|
53
52
|
this.ERROR_MESSAGE = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
|
|
53
|
+
this.paramProperties = [];
|
|
54
|
+
}
|
|
55
|
+
get paramPath() {
|
|
56
|
+
return this.paramProperties.map(property => `/{${property.key}}`).join("");
|
|
54
57
|
}
|
|
55
58
|
get Params() {
|
|
56
59
|
var _a;
|
|
@@ -84,18 +87,17 @@ class RequestType extends ReqResType_1.default {
|
|
|
84
87
|
setRequest(request) {
|
|
85
88
|
var _a, _b, _c;
|
|
86
89
|
this.createBody(request);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// }
|
|
90
|
+
this.params = {};
|
|
91
|
+
if (request.params !== undefined) {
|
|
92
|
+
for (const [key, value] of Object.entries(request.params)) {
|
|
93
|
+
const index = this.paramProperties.findIndex(property => property.key === key);
|
|
94
|
+
if (index === -1) {
|
|
95
|
+
throw new Error(`${key} is not set in paramProperties.`);
|
|
96
|
+
}
|
|
97
|
+
const property = this.paramProperties[index];
|
|
98
|
+
this.params[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${index})`], false);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
99
101
|
this.params = (_a = request.params) !== null && _a !== void 0 ? _a : {};
|
|
100
102
|
this.headers = (_b = request.headers) !== null && _b !== void 0 ? _b : {};
|
|
101
103
|
this.remoteAddress = (_c = request.socket) === null || _c === void 0 ? void 0 : _c.remoteAddress;
|
|
@@ -108,47 +110,58 @@ class RequestType extends ReqResType_1.default {
|
|
|
108
110
|
* @param {any} value - The value that caused the error. エラーを引き起こした値
|
|
109
111
|
* @returns {string} The generated error message. 生成されたエラーメッセージ
|
|
110
112
|
*/
|
|
111
|
-
|
|
113
|
+
throwInputError(code, keys, value) {
|
|
112
114
|
const list = {
|
|
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
|
-
"
|
|
115
|
+
"REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
|
|
116
|
+
"REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
|
|
117
|
+
"OBJECT_01": this.ERROR_MESSAGE.INVALID_OBJECT,
|
|
118
|
+
"ARRAY_01": this.ERROR_MESSAGE.INVALID_ARRAY,
|
|
119
|
+
"UNNECESSARY_01": this.ERROR_MESSAGE.UNNECESSARY,
|
|
120
|
+
"REQUIRE_11": this.ERROR_MESSAGE.REQUIRED,
|
|
121
|
+
"OBJECT_11": this.ERROR_MESSAGE.INVALID_OBJECT,
|
|
122
|
+
"ARRAY_11": this.ERROR_MESSAGE.INVALID_ARRAY,
|
|
123
|
+
"UNNECESSARY_11": this.ERROR_MESSAGE.UNNECESSARY,
|
|
124
|
+
"NUMBER_21": this.ERROR_MESSAGE.INVALID_NUMBER,
|
|
125
|
+
"BOOL_21": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
126
|
+
"BOOL_22": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
127
|
+
"BOOL_23": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
128
|
+
"STRING_21": this.ERROR_MESSAGE.INVALID_STRING,
|
|
129
|
+
"UUID_21": this.ERROR_MESSAGE.INVALID_UUID,
|
|
130
|
+
"MAIL_21": this.ERROR_MESSAGE.INVALID_MAIL,
|
|
131
|
+
"DATE_21": this.ERROR_MESSAGE.INVALID_DATE,
|
|
132
|
+
"DATE_22": this.ERROR_MESSAGE.INVALID_DATE,
|
|
133
|
+
"TIME_21": this.ERROR_MESSAGE.INVALID_TIME,
|
|
134
|
+
"DATETIME_21": this.ERROR_MESSAGE.INVALID_DATETIME,
|
|
135
|
+
"DATETIME_22": this.ERROR_MESSAGE.INVALID_DATETIME,
|
|
136
|
+
"HTTPS_21": this.ERROR_MESSAGE.INVALID_HTTPS,
|
|
137
|
+
"BASE64_21": this.ERROR_MESSAGE.INVALID_BASE64,
|
|
138
|
+
"REQUIRE_31": this.ERROR_MESSAGE.REQUIRED,
|
|
139
|
+
"NUMBER_41": this.ERROR_MESSAGE.INVALID_NUMBER,
|
|
140
|
+
"STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
|
|
141
|
+
"ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
|
|
142
|
+
"ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
|
|
143
|
+
"NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
|
|
144
|
+
"BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
145
|
+
"BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
146
|
+
"BOOL_93": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
147
|
+
"STRING_91": this.ERROR_MESSAGE.INVALID_STRING,
|
|
148
|
+
"UUID_91": this.ERROR_MESSAGE.INVALID_UUID,
|
|
149
|
+
"MAIL_91": this.ERROR_MESSAGE.INVALID_MAIL,
|
|
150
|
+
"DATE_91": this.ERROR_MESSAGE.INVALID_DATE,
|
|
151
|
+
"DATE_92": this.ERROR_MESSAGE.INVALID_DATE,
|
|
152
|
+
"TIME_91": this.ERROR_MESSAGE.INVALID_TIME,
|
|
153
|
+
"DATETIME_91": this.ERROR_MESSAGE.INVALID_DATETIME,
|
|
154
|
+
"DATETIME_92": this.ERROR_MESSAGE.INVALID_DATETIME,
|
|
155
|
+
"HTTPS_91": this.ERROR_MESSAGE.INVALID_HTTPS,
|
|
156
|
+
"BASE64_91": this.ERROR_MESSAGE.INVALID_BASE64,
|
|
144
157
|
};
|
|
145
158
|
let errorMessage = list[code];
|
|
146
|
-
if (code === "
|
|
159
|
+
if (code === "ENUM_41" || code === "ENUM_42") {
|
|
147
160
|
const property = this.getProperty(keys);
|
|
148
161
|
errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums).join(','));
|
|
149
162
|
}
|
|
150
163
|
errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
|
|
151
|
-
|
|
164
|
+
throw new Exception_1.InputErrorException(code, errorMessage);
|
|
152
165
|
}
|
|
153
166
|
/**
|
|
154
167
|
* Sets the values of the request body to the class properties.
|
|
@@ -197,7 +210,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
197
210
|
continue;
|
|
198
211
|
}
|
|
199
212
|
else {
|
|
200
|
-
|
|
213
|
+
this.throwInputError("REQUIRE_00", [key, 0], "");
|
|
201
214
|
}
|
|
202
215
|
}
|
|
203
216
|
else {
|
|
@@ -206,7 +219,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
206
219
|
continue;
|
|
207
220
|
}
|
|
208
221
|
else {
|
|
209
|
-
|
|
222
|
+
this.throwInputError("REQUIRE_01", [key], "");
|
|
210
223
|
}
|
|
211
224
|
}
|
|
212
225
|
}
|
|
@@ -218,7 +231,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
218
231
|
this.setObject([key], value);
|
|
219
232
|
}
|
|
220
233
|
else {
|
|
221
|
-
|
|
234
|
+
this.throwInputError("OBJECT_01", [key], value);
|
|
222
235
|
}
|
|
223
236
|
break;
|
|
224
237
|
case 'array':
|
|
@@ -230,10 +243,10 @@ class RequestType extends ReqResType_1.default {
|
|
|
230
243
|
if (request.method === 'GET' || request.method === 'DELETE') {
|
|
231
244
|
// GET,DELETEメソッドの場合、?array=1&array=2で配列となるが、
|
|
232
245
|
// ?array=1のみで終わる場合は配列にならないため、直接配列にしている
|
|
233
|
-
this.data[key] = [this.convertValue(this.properties[key].properties.type, value, [key, 0])];
|
|
246
|
+
this.data[key] = [this.convertValue(this.properties[key].properties.type, value, [key, 0], true)];
|
|
234
247
|
}
|
|
235
248
|
else {
|
|
236
|
-
|
|
249
|
+
this.throwInputError("ARRAY_01", [key], value);
|
|
237
250
|
}
|
|
238
251
|
}
|
|
239
252
|
break;
|
|
@@ -249,7 +262,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
249
262
|
// 不要項目チェック
|
|
250
263
|
for (const [key, value] of Object.entries(this.data)) {
|
|
251
264
|
if (key in this.properties === false) {
|
|
252
|
-
|
|
265
|
+
this.throwInputError("UNNECESSARY_01", [key], value);
|
|
253
266
|
}
|
|
254
267
|
}
|
|
255
268
|
}
|
|
@@ -271,14 +284,14 @@ class RequestType extends ReqResType_1.default {
|
|
|
271
284
|
this.changeBody(keys, null);
|
|
272
285
|
}
|
|
273
286
|
else {
|
|
274
|
-
|
|
287
|
+
this.throwInputError("ENUM_41", keys, value);
|
|
275
288
|
}
|
|
276
289
|
}
|
|
277
290
|
switch (enumType) {
|
|
278
291
|
case 'number':
|
|
279
292
|
case 'number?':
|
|
280
293
|
if (this.isNumber(value) === false) {
|
|
281
|
-
|
|
294
|
+
this.throwInputError("NUMBER_41", keys, value);
|
|
282
295
|
}
|
|
283
296
|
value = Number(value);
|
|
284
297
|
break;
|
|
@@ -292,12 +305,12 @@ class RequestType extends ReqResType_1.default {
|
|
|
292
305
|
value = value;
|
|
293
306
|
break;
|
|
294
307
|
default:
|
|
295
|
-
|
|
308
|
+
this.throwInputError("STRING_41", keys, value);
|
|
296
309
|
}
|
|
297
310
|
break;
|
|
298
311
|
}
|
|
299
312
|
if (Object.keys(property.enums).includes(value.toString()) === false) {
|
|
300
|
-
|
|
313
|
+
this.throwInputError("ENUM_42", keys, value);
|
|
301
314
|
}
|
|
302
315
|
this.changeBody(keys, value);
|
|
303
316
|
}
|
|
@@ -324,7 +337,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
324
337
|
continue;
|
|
325
338
|
}
|
|
326
339
|
else {
|
|
327
|
-
|
|
340
|
+
this.throwInputError("REQUIRE_31", [...keys, i], "");
|
|
328
341
|
}
|
|
329
342
|
}
|
|
330
343
|
switch (property.properties.type) {
|
|
@@ -420,7 +433,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
420
433
|
continue;
|
|
421
434
|
}
|
|
422
435
|
else {
|
|
423
|
-
|
|
436
|
+
this.throwInputError("REQUIRE_11", [...keys, key], "");
|
|
424
437
|
}
|
|
425
438
|
}
|
|
426
439
|
const value = values[key];
|
|
@@ -431,7 +444,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
431
444
|
this.setObject([...keys, key], value);
|
|
432
445
|
}
|
|
433
446
|
else {
|
|
434
|
-
|
|
447
|
+
this.throwInputError("OBJECT_11", [...keys, key], value);
|
|
435
448
|
}
|
|
436
449
|
break;
|
|
437
450
|
case 'array':
|
|
@@ -440,7 +453,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
440
453
|
this.setArray([...keys, key], value);
|
|
441
454
|
}
|
|
442
455
|
else {
|
|
443
|
-
|
|
456
|
+
this.throwInputError("ARRAY_11", [...keys, key], value);
|
|
444
457
|
}
|
|
445
458
|
break;
|
|
446
459
|
case 'enum':
|
|
@@ -455,7 +468,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
455
468
|
// unnecessary input check
|
|
456
469
|
for (const [key, value] of Object.entries(values)) {
|
|
457
470
|
if (key in property.properties === false) {
|
|
458
|
-
|
|
471
|
+
this.throwInputError("UNNECESSARY_11", [...keys, key], value);
|
|
459
472
|
}
|
|
460
473
|
}
|
|
461
474
|
}
|
|
@@ -474,12 +487,12 @@ class RequestType extends ReqResType_1.default {
|
|
|
474
487
|
* @returns {any} The converted value, 変換された値
|
|
475
488
|
* @throws {InputErrorException} Thrown if type conversion fails, 型変換に失敗した場合にスローされます
|
|
476
489
|
*/
|
|
477
|
-
convertValue(type, value, keys) {
|
|
490
|
+
convertValue(type, value, keys, isRequestBody) {
|
|
478
491
|
switch (type) {
|
|
479
492
|
case 'number':
|
|
480
493
|
case 'number?':
|
|
481
494
|
if (this.isNumber(value) === false) {
|
|
482
|
-
|
|
495
|
+
this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
|
|
483
496
|
}
|
|
484
497
|
return Number(value);
|
|
485
498
|
case 'boolean':
|
|
@@ -489,16 +502,16 @@ class RequestType extends ReqResType_1.default {
|
|
|
489
502
|
return value;
|
|
490
503
|
case 'number':
|
|
491
504
|
if (value !== 0 && value !== 1) {
|
|
492
|
-
|
|
505
|
+
this.throwInputError(isRequestBody ? "BOOL_21" : "BOOL_91", keys, value);
|
|
493
506
|
}
|
|
494
507
|
return value === 1 ? true : false;
|
|
495
508
|
case 'string':
|
|
496
509
|
if (value !== 'true' && value !== 'false') {
|
|
497
|
-
|
|
510
|
+
this.throwInputError(isRequestBody ? "BOOL_22" : "BOOL_92", keys, value);
|
|
498
511
|
}
|
|
499
512
|
return value === 'true' ? true : false;
|
|
500
513
|
default:
|
|
501
|
-
|
|
514
|
+
this.throwInputError(isRequestBody ? "BOOL_23" : "BOOL_93", keys, value);
|
|
502
515
|
}
|
|
503
516
|
case 'string':
|
|
504
517
|
case 'string?':
|
|
@@ -508,27 +521,27 @@ class RequestType extends ReqResType_1.default {
|
|
|
508
521
|
case 'string':
|
|
509
522
|
return value;
|
|
510
523
|
default:
|
|
511
|
-
|
|
524
|
+
this.throwInputError(isRequestBody ? "STRING_21" : "STRING_91", keys, value);
|
|
512
525
|
}
|
|
513
526
|
case 'uuid':
|
|
514
527
|
case 'uuid?':
|
|
515
528
|
if (this.isUUID(value)) {
|
|
516
529
|
return value;
|
|
517
530
|
}
|
|
518
|
-
|
|
531
|
+
this.throwInputError(isRequestBody ? "UUID_21" : "UUID_91", keys, value);
|
|
519
532
|
case 'mail':
|
|
520
533
|
case 'mail?':
|
|
521
534
|
if (this.isMail(value)) {
|
|
522
535
|
return value;
|
|
523
536
|
}
|
|
524
|
-
|
|
537
|
+
this.throwInputError(isRequestBody ? "MAIL_21" : "MAIL_91", keys, value);
|
|
525
538
|
case 'date':
|
|
526
539
|
case 'date?':
|
|
527
540
|
if (this.isYYYYMMDD(value) === false) {
|
|
528
|
-
|
|
541
|
+
this.throwInputError(isRequestBody ? "DATE_21" : "DATE_91", keys, value);
|
|
529
542
|
}
|
|
530
543
|
if (this.isErrorDateTime(value)) {
|
|
531
|
-
|
|
544
|
+
this.throwInputError(isRequestBody ? "DATE_22" : "DATE_92", keys, value);
|
|
532
545
|
}
|
|
533
546
|
return value;
|
|
534
547
|
case 'time':
|
|
@@ -536,17 +549,17 @@ class RequestType extends ReqResType_1.default {
|
|
|
536
549
|
if (this.isHHMM(value)) {
|
|
537
550
|
return `${value}`;
|
|
538
551
|
}
|
|
539
|
-
|
|
552
|
+
this.throwInputError(isRequestBody ? "TIME_21" : "TIME_91", keys, value);
|
|
540
553
|
case 'datetime':
|
|
541
554
|
case 'datetime?':
|
|
542
555
|
if (this.isYYYYMMDDhhmi(value)) {
|
|
543
556
|
value += ':00';
|
|
544
557
|
}
|
|
545
558
|
if (this.isYYYYMMDDhhmiss(value) === false) {
|
|
546
|
-
|
|
559
|
+
this.throwInputError(isRequestBody ? "DATETIME_21" : "DATETIME_91", keys, value);
|
|
547
560
|
}
|
|
548
561
|
if (this.isErrorDateTime(value)) {
|
|
549
|
-
|
|
562
|
+
this.throwInputError(isRequestBody ? "DATETIME_22" : "DATETIME_92", keys, value);
|
|
550
563
|
}
|
|
551
564
|
return value.replace('T', ' ');
|
|
552
565
|
case 'https':
|
|
@@ -554,13 +567,13 @@ class RequestType extends ReqResType_1.default {
|
|
|
554
567
|
if (this.isHttps(value)) {
|
|
555
568
|
return value;
|
|
556
569
|
}
|
|
557
|
-
|
|
570
|
+
this.throwInputError(isRequestBody ? "HTTPS_21" : "HTTPS_91", keys, value);
|
|
558
571
|
case 'base64':
|
|
559
572
|
case 'base64?':
|
|
560
573
|
if (this.isBase64(value)) {
|
|
561
574
|
return value;
|
|
562
575
|
}
|
|
563
|
-
|
|
576
|
+
this.throwInputError(isRequestBody ? "BASE64_21" : "BASE64_91", keys, value);
|
|
564
577
|
}
|
|
565
578
|
return value;
|
|
566
579
|
}
|
|
@@ -578,7 +591,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
578
591
|
*/
|
|
579
592
|
convertInput(keys, value) {
|
|
580
593
|
const property = this.getProperty(keys);
|
|
581
|
-
this.changeBody(keys, this.convertValue(property.type, value, keys));
|
|
594
|
+
this.changeBody(keys, this.convertValue(property.type, value, keys, true));
|
|
582
595
|
}
|
|
583
596
|
// ****************************************************************************
|
|
584
597
|
// for create swagger
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosResponse } from "axios";
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
3
|
import { Pool, PoolClient } from 'pg';
|
|
4
|
-
import { IncomingHttpHeaders } from './src/reqestResponse/RequestType';
|
|
4
|
+
import { ErrorMessageType, IncomingHttpHeaders } from './src/reqestResponse/RequestType';
|
|
5
5
|
import { ArrayType, EnumType, ObjectType, PrimitiveType } from './src/reqestResponse/ReqResType';
|
|
6
6
|
import { AwsS3Client } from './src/clients/AwsS3Client';
|
|
7
7
|
import { Base64Client } from './src/clients/Base64Client';
|
|
@@ -85,22 +85,8 @@ declare module 'pg-mvc-service' {
|
|
|
85
85
|
constructor();
|
|
86
86
|
|
|
87
87
|
protected properties: { [key: string]: PropertyType; };
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
public readonly REQUIRED_ERROR_MESSAGE: string;
|
|
91
|
-
public readonly UNNECESSARY_INPUT_ERROR_MESSAGE: string;
|
|
92
|
-
public readonly INVALID_OBJECT_ERROR_MESSAGE: string;
|
|
93
|
-
public readonly INVALID_ARRAY_ERROR_MESSAGE: string;
|
|
94
|
-
public readonly INVALID_NUMBER_ERROR_MESSAGE: string;
|
|
95
|
-
public readonly INVALID_BOOL_ERROR_MESSAGE: string;
|
|
96
|
-
public readonly INVALID_STRING_ERROR_MESSAGE: string;
|
|
97
|
-
public readonly INVALID_UUID_ERROR_MESSAGE: string;
|
|
98
|
-
public readonly INVALID_MAIL_ERROR_MESSAGE: string;
|
|
99
|
-
public readonly INVALID_DATE_ERROR_MESSAGE: string;
|
|
100
|
-
public readonly INVALID_TIME_ERROR_MESSAGE: string;
|
|
101
|
-
public readonly INVALID_DATETIME_ERROR_MESSAGE: string;
|
|
102
|
-
public readonly INVALID_BASE64_ERROR_MESSAGE: string;
|
|
103
|
-
public readonly INVALID_ENUM_ERROR_MESSAGE: string;
|
|
88
|
+
protected paramProperties: Array<(PrimitiveType | EnumType) & { key: string }>;
|
|
89
|
+
protected readonly ERROR_MESSAGE: ErrorMessageType;
|
|
104
90
|
|
|
105
91
|
protected throwException(code: string, message: string): never;
|
|
106
92
|
|
package/package.json
CHANGED
package/src/Service.ts
CHANGED
|
@@ -16,7 +16,7 @@ export class Service {
|
|
|
16
16
|
protected readonly method: MethodType = 'GET';
|
|
17
17
|
get Method(): MethodType { return this.method; }
|
|
18
18
|
protected readonly endpoint: string = '';
|
|
19
|
-
get Endpoint(): string { return this.endpoint; }
|
|
19
|
+
get Endpoint(): string { return this.endpoint + this.request.paramPath; }
|
|
20
20
|
protected readonly apiCode: string = '';
|
|
21
21
|
get ApiCode(): string { return this.apiCode; }
|
|
22
22
|
protected readonly summary: string = '';
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
-
import ReqResType from "./ReqResType";
|
|
2
|
+
import ReqResType, { EnumType, PrimitiveType, PropertyType } from "./ReqResType";
|
|
3
3
|
import { InputErrorException } from '../exceptions/Exception';
|
|
4
4
|
|
|
5
|
+
// エラーメッセージの型定義
|
|
6
|
+
export interface ErrorMessageType {
|
|
7
|
+
REQUIRED: string;
|
|
8
|
+
UNNECESSARY: string;
|
|
9
|
+
INVALID_OBJECT: string;
|
|
10
|
+
INVALID_ARRAY: string;
|
|
11
|
+
INVALID_NUMBER: string;
|
|
12
|
+
INVALID_BOOL: string;
|
|
13
|
+
INVALID_STRING: string;
|
|
14
|
+
INVALID_UUID: string;
|
|
15
|
+
INVALID_MAIL: string;
|
|
16
|
+
INVALID_HTTPS: string;
|
|
17
|
+
INVALID_DATE: string;
|
|
18
|
+
INVALID_TIME: string;
|
|
19
|
+
INVALID_DATETIME: string;
|
|
20
|
+
INVALID_BASE64: string;
|
|
21
|
+
INVALID_ENUM: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
5
24
|
export class RequestType extends ReqResType {
|
|
6
25
|
|
|
7
26
|
// *****************************************
|
|
@@ -10,7 +29,7 @@ export class RequestType extends ReqResType {
|
|
|
10
29
|
// エラー文言
|
|
11
30
|
// エラーメッセージの変更はサブクラスで行ってください
|
|
12
31
|
// *****************************************
|
|
13
|
-
|
|
32
|
+
private readonly ERROR_MESSAGE_ENGLISH: ErrorMessageType = {
|
|
14
33
|
REQUIRED: '{property} is required.',
|
|
15
34
|
UNNECESSARY: '{property} is unnecessary input. ',
|
|
16
35
|
INVALID_OBJECT: '{property} must be of type Object. ({value})',
|
|
@@ -27,25 +46,29 @@ export class RequestType extends ReqResType {
|
|
|
27
46
|
INVALID_BASE64: '{property} must be in Base64 format. ({value})',
|
|
28
47
|
INVALID_ENUM: '{property} must be in {enums}. ({value})'
|
|
29
48
|
}
|
|
30
|
-
|
|
31
|
-
BODY_REQUIRED: 'リクエストボディが必要です。',
|
|
49
|
+
private readonly ERROR_MESSAGE_JAPAN: ErrorMessageType = {
|
|
32
50
|
REQUIRED: '{property}は必須項目です。',
|
|
33
51
|
UNNECESSARY: '{property}は不要な入力です。',
|
|
34
|
-
INVALID_OBJECT: '{property}
|
|
35
|
-
INVALID_ARRAY: '{property}
|
|
36
|
-
INVALID_NUMBER: '{property}
|
|
37
|
-
INVALID_BOOL: '{property}
|
|
38
|
-
INVALID_STRING: '{property}
|
|
39
|
-
INVALID_UUID: '{property}はUUID
|
|
40
|
-
INVALID_MAIL: '{property}
|
|
41
|
-
INVALID_HTTPS: '{property}はhttpsまたはhttpのURL
|
|
42
|
-
INVALID_DATE: '{property}は"YYYY-MM-DD"
|
|
43
|
-
INVALID_TIME: '{property}は"hh:mi"
|
|
44
|
-
INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"
|
|
45
|
-
INVALID_BASE64: '{property}はBase64
|
|
46
|
-
INVALID_ENUM: '{property}は{enums}
|
|
52
|
+
INVALID_OBJECT: '{property}はobject型で入力してください。({value})',
|
|
53
|
+
INVALID_ARRAY: '{property}はarray型で入力してください。({value})',
|
|
54
|
+
INVALID_NUMBER: '{property}はnumber型または半角数値のstring型で入力してください。({value})',
|
|
55
|
+
INVALID_BOOL: '{property}はboolean型またはtrue、falseのstring型または0、1のnumber型で入力してください。({value})',
|
|
56
|
+
INVALID_STRING: '{property}はstring型で入力してください。({value})',
|
|
57
|
+
INVALID_UUID: '{property}はUUID形式のstring型で入力してください。({value})',
|
|
58
|
+
INVALID_MAIL: '{property}はメールアドレス形式のstring型で入力してください。({value})',
|
|
59
|
+
INVALID_HTTPS: '{property}はhttpsまたはhttpのURL形式のstring型で入力してください。({value})',
|
|
60
|
+
INVALID_DATE: '{property}は"YYYY-MM-DD"形式のstring型で入力してください。({value})',
|
|
61
|
+
INVALID_TIME: '{property}は"hh:mi"形式のstring型で入力してください。({value})',
|
|
62
|
+
INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式のstring型で入力してください。({value})',
|
|
63
|
+
INVALID_BASE64: '{property}はBase64形式のstring型で入力してください。({value})',
|
|
64
|
+
INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})'
|
|
65
|
+
}
|
|
66
|
+
protected readonly ERROR_MESSAGE: ErrorMessageType = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
|
|
67
|
+
|
|
68
|
+
protected paramProperties: Array<(PrimitiveType | EnumType) & { key: string }> = []
|
|
69
|
+
get paramPath(): string {
|
|
70
|
+
return this.paramProperties.map(property => `/{${property.key}}`).join("");
|
|
47
71
|
}
|
|
48
|
-
public readonly ERROR_MESSAGE = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
|
|
49
72
|
|
|
50
73
|
private params?: {[key: string]: any};
|
|
51
74
|
get Params(): {[key: string]: any} {
|
|
@@ -80,18 +103,18 @@ export class RequestType extends ReqResType {
|
|
|
80
103
|
|
|
81
104
|
public setRequest(request: Request) {
|
|
82
105
|
this.createBody(request);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
106
|
+
|
|
107
|
+
this.params = {};
|
|
108
|
+
if (request.params !== undefined) {
|
|
109
|
+
for (const [key, value] of Object.entries(request.params)) {
|
|
110
|
+
const index = this.paramProperties.findIndex(property => property.key === key);
|
|
111
|
+
if (index === -1) {
|
|
112
|
+
throw new Error(`${key} is not set in paramProperties.`);
|
|
113
|
+
}
|
|
114
|
+
const property = this.paramProperties[index];
|
|
115
|
+
this.params[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${index})`], false);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
95
118
|
this.params = request.params ?? {};
|
|
96
119
|
this.headers = request.headers ?? {};
|
|
97
120
|
|
|
@@ -105,52 +128,71 @@ export class RequestType extends ReqResType {
|
|
|
105
128
|
* @param {Array<string | number>} keys - The keys indicating the property path. プロパティパスを示すキー
|
|
106
129
|
* @param {any} value - The value that caused the error. エラーを引き起こした値
|
|
107
130
|
* @returns {string} The generated error message. 生成されたエラーメッセージ
|
|
108
|
-
*/
|
|
109
|
-
private
|
|
110
|
-
"
|
|
111
|
-
"
|
|
131
|
+
*/
|
|
132
|
+
private throwInputError(code:
|
|
133
|
+
"REQUIRE_00" | "REQUIRE_01" | "OBJECT_01" | "ARRAY_01" | "UNNECESSARY_01" |
|
|
134
|
+
"REQUIRE_11" | "OBJECT_11" | "ARRAY_11" | "UNNECESSARY_11" |
|
|
135
|
+
"NUMBER_21" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
|
|
136
|
+
"TIME_21" | "DATETIME_21" | "DATETIME_22" | "HTTPS_21" | "BASE64_21" |
|
|
137
|
+
"REQUIRE_31" |
|
|
138
|
+
"ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
|
|
139
|
+
"NUMBER_91" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
|
|
140
|
+
"TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
|
|
141
|
+
, keys: Array<string | number>, value: any): never {
|
|
112
142
|
const list = {
|
|
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
|
-
"
|
|
143
|
+
"REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
|
|
144
|
+
"REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
|
|
145
|
+
"OBJECT_01": this.ERROR_MESSAGE.INVALID_OBJECT,
|
|
146
|
+
"ARRAY_01": this.ERROR_MESSAGE.INVALID_ARRAY,
|
|
147
|
+
"UNNECESSARY_01": this.ERROR_MESSAGE.UNNECESSARY,
|
|
148
|
+
"REQUIRE_11": this.ERROR_MESSAGE.REQUIRED,
|
|
149
|
+
"OBJECT_11": this.ERROR_MESSAGE.INVALID_OBJECT,
|
|
150
|
+
"ARRAY_11": this.ERROR_MESSAGE.INVALID_ARRAY,
|
|
151
|
+
"UNNECESSARY_11": this.ERROR_MESSAGE.UNNECESSARY,
|
|
152
|
+
"NUMBER_21": this.ERROR_MESSAGE.INVALID_NUMBER,
|
|
153
|
+
"BOOL_21": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
154
|
+
"BOOL_22": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
155
|
+
"BOOL_23": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
156
|
+
"STRING_21": this.ERROR_MESSAGE.INVALID_STRING,
|
|
157
|
+
"UUID_21": this.ERROR_MESSAGE.INVALID_UUID,
|
|
158
|
+
"MAIL_21": this.ERROR_MESSAGE.INVALID_MAIL,
|
|
159
|
+
"DATE_21": this.ERROR_MESSAGE.INVALID_DATE,
|
|
160
|
+
"DATE_22": this.ERROR_MESSAGE.INVALID_DATE,
|
|
161
|
+
"TIME_21": this.ERROR_MESSAGE.INVALID_TIME,
|
|
162
|
+
"DATETIME_21": this.ERROR_MESSAGE.INVALID_DATETIME,
|
|
163
|
+
"DATETIME_22": this.ERROR_MESSAGE.INVALID_DATETIME,
|
|
164
|
+
"HTTPS_21": this.ERROR_MESSAGE.INVALID_HTTPS,
|
|
165
|
+
"BASE64_21": this.ERROR_MESSAGE.INVALID_BASE64,
|
|
166
|
+
"REQUIRE_31": this.ERROR_MESSAGE.REQUIRED,
|
|
167
|
+
"NUMBER_41": this.ERROR_MESSAGE.INVALID_NUMBER,
|
|
168
|
+
"STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
|
|
169
|
+
"ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
|
|
170
|
+
"ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
|
|
171
|
+
"NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
|
|
172
|
+
"BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
173
|
+
"BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
174
|
+
"BOOL_93": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
175
|
+
"STRING_91": this.ERROR_MESSAGE.INVALID_STRING,
|
|
176
|
+
"UUID_91": this.ERROR_MESSAGE.INVALID_UUID,
|
|
177
|
+
"MAIL_91": this.ERROR_MESSAGE.INVALID_MAIL,
|
|
178
|
+
"DATE_91": this.ERROR_MESSAGE.INVALID_DATE,
|
|
179
|
+
"DATE_92": this.ERROR_MESSAGE.INVALID_DATE,
|
|
180
|
+
"TIME_91": this.ERROR_MESSAGE.INVALID_TIME,
|
|
181
|
+
"DATETIME_91": this.ERROR_MESSAGE.INVALID_DATETIME,
|
|
182
|
+
"DATETIME_92": this.ERROR_MESSAGE.INVALID_DATETIME,
|
|
183
|
+
"HTTPS_91": this.ERROR_MESSAGE.INVALID_HTTPS,
|
|
184
|
+
"BASE64_91": this.ERROR_MESSAGE.INVALID_BASE64,
|
|
144
185
|
}
|
|
145
186
|
|
|
146
|
-
let errorMessage =
|
|
147
|
-
if (code === "
|
|
187
|
+
let errorMessage = list[code];
|
|
188
|
+
if (code === "ENUM_41" || code === "ENUM_42") {
|
|
148
189
|
const property = this.getProperty(keys);
|
|
149
190
|
errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums).join(','));
|
|
150
191
|
}
|
|
151
192
|
|
|
152
|
-
errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value)
|
|
153
|
-
|
|
193
|
+
errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
|
|
194
|
+
|
|
195
|
+
throw new InputErrorException(code, errorMessage);
|
|
154
196
|
}
|
|
155
197
|
|
|
156
198
|
/**
|
|
@@ -200,14 +242,14 @@ export class RequestType extends ReqResType {
|
|
|
200
242
|
}
|
|
201
243
|
continue;
|
|
202
244
|
} else {
|
|
203
|
-
|
|
245
|
+
this.throwInputError("REQUIRE_00", [key, 0], "");
|
|
204
246
|
}
|
|
205
247
|
} else {
|
|
206
248
|
if (this.properties[key].type.endsWith('?')) {
|
|
207
249
|
this.changeBody([key], null);
|
|
208
250
|
continue;
|
|
209
251
|
} else {
|
|
210
|
-
|
|
252
|
+
this.throwInputError("REQUIRE_01", [key], "");
|
|
211
253
|
}
|
|
212
254
|
}
|
|
213
255
|
}
|
|
@@ -219,7 +261,7 @@ export class RequestType extends ReqResType {
|
|
|
219
261
|
if (typeof value === 'object') {
|
|
220
262
|
this.setObject([key], value);
|
|
221
263
|
} else {
|
|
222
|
-
|
|
264
|
+
this.throwInputError("OBJECT_01", [key], value);
|
|
223
265
|
}
|
|
224
266
|
break;
|
|
225
267
|
case 'array':
|
|
@@ -230,9 +272,9 @@ export class RequestType extends ReqResType {
|
|
|
230
272
|
if (request.method === 'GET' || request.method === 'DELETE') {
|
|
231
273
|
// GET,DELETEメソッドの場合、?array=1&array=2で配列となるが、
|
|
232
274
|
// ?array=1のみで終わる場合は配列にならないため、直接配列にしている
|
|
233
|
-
this.data[key] = [this.convertValue(this.properties[key].properties.type, value, [key, 0])];
|
|
275
|
+
this.data[key] = [this.convertValue(this.properties[key].properties.type, value, [key, 0], true)];
|
|
234
276
|
} else {
|
|
235
|
-
|
|
277
|
+
this.throwInputError("ARRAY_01", [key], value);
|
|
236
278
|
}
|
|
237
279
|
}
|
|
238
280
|
break;
|
|
@@ -249,7 +291,7 @@ export class RequestType extends ReqResType {
|
|
|
249
291
|
// 不要項目チェック
|
|
250
292
|
for (const [key, value] of Object.entries(this.data)) {
|
|
251
293
|
if (key in this.properties === false) {
|
|
252
|
-
|
|
294
|
+
this.throwInputError("UNNECESSARY_01", [key], value);
|
|
253
295
|
}
|
|
254
296
|
}
|
|
255
297
|
}
|
|
@@ -272,7 +314,7 @@ export class RequestType extends ReqResType {
|
|
|
272
314
|
if (enumType.endsWith('?')) {
|
|
273
315
|
this.changeBody(keys, null);
|
|
274
316
|
} else {
|
|
275
|
-
|
|
317
|
+
this.throwInputError("ENUM_41", keys, value);
|
|
276
318
|
}
|
|
277
319
|
}
|
|
278
320
|
|
|
@@ -280,7 +322,7 @@ export class RequestType extends ReqResType {
|
|
|
280
322
|
case 'number':
|
|
281
323
|
case 'number?':
|
|
282
324
|
if (this.isNumber(value) === false) {
|
|
283
|
-
|
|
325
|
+
this.throwInputError("NUMBER_41", keys, value);
|
|
284
326
|
}
|
|
285
327
|
value = Number(value);
|
|
286
328
|
break;
|
|
@@ -294,13 +336,13 @@ export class RequestType extends ReqResType {
|
|
|
294
336
|
value = value;
|
|
295
337
|
break;
|
|
296
338
|
default:
|
|
297
|
-
|
|
339
|
+
this.throwInputError("STRING_41", keys, value);
|
|
298
340
|
}
|
|
299
341
|
break;
|
|
300
342
|
}
|
|
301
343
|
|
|
302
344
|
if (Object.keys(property.enums).includes(value.toString()) === false) {
|
|
303
|
-
|
|
345
|
+
this.throwInputError("ENUM_42", keys, value);
|
|
304
346
|
}
|
|
305
347
|
|
|
306
348
|
this.changeBody(keys, value);
|
|
@@ -329,7 +371,7 @@ export class RequestType extends ReqResType {
|
|
|
329
371
|
this.changeBody([...keys, i], values[i] === undefined ? undefined : null);
|
|
330
372
|
continue;
|
|
331
373
|
} else {
|
|
332
|
-
|
|
374
|
+
this.throwInputError("REQUIRE_31", [...keys, i], "");
|
|
333
375
|
}
|
|
334
376
|
}
|
|
335
377
|
|
|
@@ -432,7 +474,7 @@ export class RequestType extends ReqResType {
|
|
|
432
474
|
this.changeBody([...keys, key], null);
|
|
433
475
|
continue;
|
|
434
476
|
} else {
|
|
435
|
-
|
|
477
|
+
this.throwInputError("REQUIRE_11", [...keys, key], "");
|
|
436
478
|
}
|
|
437
479
|
}
|
|
438
480
|
|
|
@@ -443,7 +485,7 @@ export class RequestType extends ReqResType {
|
|
|
443
485
|
if (typeof value === 'object') {
|
|
444
486
|
this.setObject([...keys, key], value);
|
|
445
487
|
} else {
|
|
446
|
-
|
|
488
|
+
this.throwInputError("OBJECT_11", [...keys, key], value);
|
|
447
489
|
}
|
|
448
490
|
break;
|
|
449
491
|
case 'array':
|
|
@@ -451,7 +493,7 @@ export class RequestType extends ReqResType {
|
|
|
451
493
|
if (Array.isArray(value)) {
|
|
452
494
|
this.setArray([...keys, key], value);
|
|
453
495
|
} else {
|
|
454
|
-
|
|
496
|
+
this.throwInputError("ARRAY_11", [...keys, key], value);
|
|
455
497
|
}
|
|
456
498
|
break;
|
|
457
499
|
case 'enum':
|
|
@@ -467,7 +509,7 @@ export class RequestType extends ReqResType {
|
|
|
467
509
|
// unnecessary input check
|
|
468
510
|
for (const [key, value] of Object.entries(values)) {
|
|
469
511
|
if (key in property.properties === false) {
|
|
470
|
-
|
|
512
|
+
this.throwInputError("UNNECESSARY_11", [...keys, key], value);
|
|
471
513
|
}
|
|
472
514
|
}
|
|
473
515
|
}
|
|
@@ -487,13 +529,13 @@ export class RequestType extends ReqResType {
|
|
|
487
529
|
* @returns {any} The converted value, 変換された値
|
|
488
530
|
* @throws {InputErrorException} Thrown if type conversion fails, 型変換に失敗した場合にスローされます
|
|
489
531
|
*/
|
|
490
|
-
private convertValue(type: string, value: any, keys: Array<string | number
|
|
532
|
+
private convertValue(type: string, value: any, keys: Array<string | number>, isRequestBody: boolean) {
|
|
491
533
|
|
|
492
534
|
switch (type) {
|
|
493
535
|
case 'number':
|
|
494
536
|
case 'number?':
|
|
495
537
|
if (this.isNumber(value) === false) {
|
|
496
|
-
|
|
538
|
+
this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
|
|
497
539
|
}
|
|
498
540
|
return Number(value);
|
|
499
541
|
case 'boolean':
|
|
@@ -503,16 +545,16 @@ export class RequestType extends ReqResType {
|
|
|
503
545
|
return value;
|
|
504
546
|
case 'number':
|
|
505
547
|
if (value !== 0 && value !== 1) {
|
|
506
|
-
|
|
548
|
+
this.throwInputError(isRequestBody ? "BOOL_21" : "BOOL_91", keys, value);
|
|
507
549
|
}
|
|
508
550
|
return value === 1 ? true : false;
|
|
509
551
|
case 'string':
|
|
510
552
|
if (value !== 'true' && value !== 'false') {
|
|
511
|
-
|
|
553
|
+
this.throwInputError(isRequestBody ? "BOOL_22" : "BOOL_92", keys, value);
|
|
512
554
|
}
|
|
513
555
|
return value === 'true' ? true : false;
|
|
514
556
|
default:
|
|
515
|
-
|
|
557
|
+
this.throwInputError(isRequestBody ? "BOOL_23" : "BOOL_93", keys, value);
|
|
516
558
|
}
|
|
517
559
|
case 'string':
|
|
518
560
|
case 'string?':
|
|
@@ -522,28 +564,28 @@ export class RequestType extends ReqResType {
|
|
|
522
564
|
case 'string':
|
|
523
565
|
return value;
|
|
524
566
|
default:
|
|
525
|
-
|
|
567
|
+
this.throwInputError(isRequestBody ? "STRING_21" : "STRING_91", keys, value);
|
|
526
568
|
}
|
|
527
569
|
case 'uuid':
|
|
528
570
|
case 'uuid?':
|
|
529
571
|
if (this.isUUID(value)) {
|
|
530
572
|
return value;
|
|
531
573
|
}
|
|
532
|
-
|
|
574
|
+
this.throwInputError(isRequestBody ? "UUID_21" : "UUID_91", keys, value);
|
|
533
575
|
case 'mail':
|
|
534
576
|
case 'mail?':
|
|
535
577
|
if (this.isMail(value)) {
|
|
536
578
|
return value;
|
|
537
579
|
}
|
|
538
|
-
|
|
580
|
+
this.throwInputError(isRequestBody ? "MAIL_21" : "MAIL_91", keys, value);
|
|
539
581
|
case 'date':
|
|
540
582
|
case 'date?':
|
|
541
583
|
if (this.isYYYYMMDD(value) === false) {
|
|
542
|
-
|
|
584
|
+
this.throwInputError(isRequestBody ? "DATE_21" : "DATE_91", keys, value);
|
|
543
585
|
}
|
|
544
586
|
|
|
545
587
|
if (this.isErrorDateTime(value)) {
|
|
546
|
-
|
|
588
|
+
this.throwInputError(isRequestBody ? "DATE_22" : "DATE_92", keys, value);
|
|
547
589
|
}
|
|
548
590
|
return value;
|
|
549
591
|
case 'time':
|
|
@@ -551,7 +593,7 @@ export class RequestType extends ReqResType {
|
|
|
551
593
|
if (this.isHHMM(value)) {
|
|
552
594
|
return `${value}`;
|
|
553
595
|
}
|
|
554
|
-
|
|
596
|
+
this.throwInputError(isRequestBody ? "TIME_21" : "TIME_91", keys, value);
|
|
555
597
|
case 'datetime':
|
|
556
598
|
case 'datetime?':
|
|
557
599
|
if (this.isYYYYMMDDhhmi(value)) {
|
|
@@ -559,11 +601,11 @@ export class RequestType extends ReqResType {
|
|
|
559
601
|
}
|
|
560
602
|
|
|
561
603
|
if (this.isYYYYMMDDhhmiss(value) === false) {
|
|
562
|
-
|
|
604
|
+
this.throwInputError(isRequestBody ? "DATETIME_21" : "DATETIME_91", keys, value);
|
|
563
605
|
}
|
|
564
606
|
|
|
565
607
|
if (this.isErrorDateTime(value)) {
|
|
566
|
-
|
|
608
|
+
this.throwInputError(isRequestBody ? "DATETIME_22" : "DATETIME_92", keys, value);
|
|
567
609
|
}
|
|
568
610
|
return value.replace('T', ' ');
|
|
569
611
|
case 'https':
|
|
@@ -571,13 +613,13 @@ export class RequestType extends ReqResType {
|
|
|
571
613
|
if (this.isHttps(value)) {
|
|
572
614
|
return value;
|
|
573
615
|
}
|
|
574
|
-
|
|
616
|
+
this.throwInputError(isRequestBody ? "HTTPS_21" : "HTTPS_91", keys, value);
|
|
575
617
|
case 'base64':
|
|
576
618
|
case 'base64?':
|
|
577
619
|
if (this.isBase64(value)) {
|
|
578
620
|
return value;
|
|
579
621
|
}
|
|
580
|
-
|
|
622
|
+
this.throwInputError(isRequestBody ? "BASE64_21" : "BASE64_91", keys, value);
|
|
581
623
|
}
|
|
582
624
|
|
|
583
625
|
return value;
|
|
@@ -597,7 +639,7 @@ export class RequestType extends ReqResType {
|
|
|
597
639
|
*/
|
|
598
640
|
private convertInput(keys: Array<string | number>, value: any) {
|
|
599
641
|
const property = this.getProperty(keys);
|
|
600
|
-
this.changeBody(keys, this.convertValue(property.type, value, keys));
|
|
642
|
+
this.changeBody(keys, this.convertValue(property.type, value, keys, true));
|
|
601
643
|
}
|
|
602
644
|
|
|
603
645
|
|