pg-mvc-service 2.0.87 → 2.0.89

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.
@@ -23,8 +23,11 @@ class RequestType extends ReqResType_1.default {
23
23
  INVALID_OBJECT: '{property} must be of type Object. ({value})',
24
24
  INVALID_ARRAY: '{property} must be of type Array. ({value})',
25
25
  INVALID_NUMBER: '{property} must be of type number. ({value})',
26
+ INVALID_NUMBER_MAX: '{property} must be less than or equal to {max}. ({value})',
27
+ INVALID_NUMBER_MIN: '{property} must be greater than or equal to {min}. ({value})',
26
28
  INVALID_BOOL: '{property} must be of type bool or a string with true, false, or a number with 0, 1. ({value})',
27
29
  INVALID_STRING: '{property} must be of type string. ({value})',
30
+ INVALID_STRING_MAX_LENGTH: '{property} must be less than or equal to {maxLength} characters. ({value})',
28
31
  INVALID_UUID: '{property} must be a UUID. ({value})',
29
32
  INVALID_MAIL: '{property} must be an email. ({value})',
30
33
  INVALID_HTTPS: '{property} must be an https or http URL. ({value})',
@@ -43,8 +46,11 @@ class RequestType extends ReqResType_1.default {
43
46
  INVALID_OBJECT: '{property}はobject型で入力してください。({value})',
44
47
  INVALID_ARRAY: '{property}はarray型で入力してください。({value})',
45
48
  INVALID_NUMBER: '{property}はnumber型または半角数値のstring型で入力してください。({value})',
49
+ INVALID_NUMBER_MAX: '{property}は{max}以下の値で入力してください。({value})',
50
+ INVALID_NUMBER_MIN: '{property}は{min}以上の値で入力してください。({value})',
46
51
  INVALID_BOOL: '{property}はboolean型またはtrue、falseのstring型または0、1のnumber型で入力してください。({value})',
47
52
  INVALID_STRING: '{property}はstring型で入力してください。({value})',
53
+ INVALID_STRING_MAX_LENGTH: '{property}は{maxLength}文字以内で入力してください。({value})',
48
54
  INVALID_UUID: '{property}はUUID形式のstring型で入力してください。({value})',
49
55
  INVALID_MAIL: '{property}はメールアドレス形式のstring型で入力してください。({value})',
50
56
  INVALID_HTTPS: '{property}はhttpsまたはhttpのURL形式のstring型で入力してください。({value})',
@@ -124,7 +130,7 @@ class RequestType extends ReqResType_1.default {
124
130
  throw new Error(`${key} is not set in paramProperties.`);
125
131
  }
126
132
  const property = this.paramProperties[index];
127
- this.params[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${index})`], false);
133
+ this.params[key] = this.convertValue(property, value, [key, `(pathIndex: ${index})`], false);
128
134
  }
129
135
  }
130
136
  this.params = (_a = request.params) !== null && _a !== void 0 ? _a : {};
@@ -140,7 +146,7 @@ class RequestType extends ReqResType_1.default {
140
146
  * @returns {string} The generated error message. 生成されたエラーメッセージ
141
147
  */
142
148
  throwInputError(code, keys, value) {
143
- var _a;
149
+ var _a, _b, _c, _d;
144
150
  const list = {
145
151
  "REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
146
152
  "REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
@@ -152,10 +158,13 @@ class RequestType extends ReqResType_1.default {
152
158
  "ARRAY_11": this.ERROR_MESSAGE.INVALID_ARRAY,
153
159
  "UNNECESSARY_11": this.ERROR_MESSAGE.UNNECESSARY,
154
160
  "NUMBER_21": this.ERROR_MESSAGE.INVALID_NUMBER,
161
+ "NUMBER_22": this.ERROR_MESSAGE.INVALID_NUMBER_MIN,
162
+ "NUMBER_23": this.ERROR_MESSAGE.INVALID_NUMBER_MAX,
155
163
  "BOOL_21": this.ERROR_MESSAGE.INVALID_BOOL,
156
164
  "BOOL_22": this.ERROR_MESSAGE.INVALID_BOOL,
157
165
  "BOOL_23": this.ERROR_MESSAGE.INVALID_BOOL,
158
166
  "STRING_21": this.ERROR_MESSAGE.INVALID_STRING,
167
+ "STRING_22": this.ERROR_MESSAGE.INVALID_STRING_MAX_LENGTH,
159
168
  "UUID_21": this.ERROR_MESSAGE.INVALID_UUID,
160
169
  "MAIL_21": this.ERROR_MESSAGE.INVALID_MAIL,
161
170
  "DATE_21": this.ERROR_MESSAGE.INVALID_DATE,
@@ -166,8 +175,6 @@ class RequestType extends ReqResType_1.default {
166
175
  "HTTPS_21": this.ERROR_MESSAGE.INVALID_HTTPS,
167
176
  "BASE64_21": this.ERROR_MESSAGE.INVALID_BASE64,
168
177
  "REQUIRE_31": this.ERROR_MESSAGE.REQUIRED,
169
- "NUMBER_31": this.ERROR_MESSAGE.INVALID_NUMBER,
170
- "STRING_31": this.ERROR_MESSAGE.INVALID_STRING,
171
178
  "ENUM_32": this.ERROR_MESSAGE.INVALID_ENUM,
172
179
  "NUMBER_41": this.ERROR_MESSAGE.INVALID_NUMBER,
173
180
  "STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
@@ -189,10 +196,13 @@ class RequestType extends ReqResType_1.default {
189
196
  "MAP_34": this.ERROR_MESSAGE.INVALID_MAP_BOOL,
190
197
  "MAP_35": this.ERROR_MESSAGE.INVALID_MAP_BOOL,
191
198
  "NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
199
+ "NUMBER_92": this.ERROR_MESSAGE.INVALID_NUMBER_MIN,
200
+ "NUMBER_93": this.ERROR_MESSAGE.INVALID_NUMBER_MAX,
192
201
  "BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
193
202
  "BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
194
203
  "BOOL_93": this.ERROR_MESSAGE.INVALID_BOOL,
195
204
  "STRING_91": this.ERROR_MESSAGE.INVALID_STRING,
205
+ "STRING_92": this.ERROR_MESSAGE.INVALID_STRING_MAX_LENGTH,
196
206
  "UUID_91": this.ERROR_MESSAGE.INVALID_UUID,
197
207
  "MAIL_91": this.ERROR_MESSAGE.INVALID_MAIL,
198
208
  "DATE_91": this.ERROR_MESSAGE.INVALID_DATE,
@@ -204,9 +214,21 @@ class RequestType extends ReqResType_1.default {
204
214
  "BASE64_91": this.ERROR_MESSAGE.INVALID_BASE64,
205
215
  };
206
216
  let errorMessage = list[code];
207
- if (code === "ENUM_32" || code === "ENUM_41" || code === "ENUM_42") {
208
- const property = this.getProperty(keys);
209
- errorMessage = errorMessage.replace('{enums}', Object.keys((_a = property.enums) !== null && _a !== void 0 ? _a : '').join(','));
217
+ const property = this.getProperty(keys);
218
+ switch (property.type) {
219
+ case 'enum':
220
+ case 'enum?':
221
+ errorMessage = errorMessage.replace('{enums}', Object.keys((_a = property.enums) !== null && _a !== void 0 ? _a : '').join(','));
222
+ break;
223
+ case 'string':
224
+ case 'string?':
225
+ errorMessage = errorMessage.replace('{maxLength}', Object.keys((_b = property.maxLength) !== null && _b !== void 0 ? _b : '').join(','));
226
+ break;
227
+ case 'number':
228
+ case 'number?':
229
+ errorMessage = errorMessage.replace('{max}', Object.keys((_c = property.max) !== null && _c !== void 0 ? _c : '').join(','));
230
+ errorMessage = errorMessage.replace('{min}', Object.keys((_d = property.min) !== null && _d !== void 0 ? _d : '').join(','));
231
+ break;
210
232
  }
211
233
  errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
212
234
  throw new Exception_1.InputErrorException(code, errorMessage);
@@ -291,7 +313,43 @@ class RequestType extends ReqResType_1.default {
291
313
  if (request.method === 'GET' || request.method === 'DELETE') {
292
314
  // GET,DELETEメソッドの場合、?array=1&array=2で配列となるが、
293
315
  // ?array=1のみで終わる場合は配列にならないため、直接配列にしている
294
- this.data[key] = [this.convertValue(this.properties[key].item.type, value, [key, 0], true)];
316
+ const type = this.properties[key].item.type;
317
+ if (type === 'object' || type === 'object?' || type === 'array' || type === 'array?' || type === 'map' || type === 'map?') {
318
+ throw new Error("GETまたはDELETEメソッドでは配列型にobject, array, mapを使用することはできません。");
319
+ }
320
+ if (type === 'enum' || type === 'enum?') {
321
+ const tempProp = {
322
+ type: type,
323
+ description: this.properties[key].item.description,
324
+ enumType: this.properties[key].item.enumType,
325
+ enums: this.properties[key].item.enums,
326
+ };
327
+ this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
328
+ }
329
+ else if (type === 'string' || type === 'string?') {
330
+ const tempProp = {
331
+ type: type,
332
+ description: this.properties[key].item.description,
333
+ maxLength: this.properties[key].item.maxLength,
334
+ };
335
+ this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
336
+ }
337
+ else if (type === 'number' || type === 'number?') {
338
+ const tempProp = {
339
+ type: type,
340
+ description: this.properties[key].item.description,
341
+ max: this.properties[key].item.max,
342
+ min: this.properties[key].item.min,
343
+ };
344
+ this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
345
+ }
346
+ else {
347
+ const tempProp = {
348
+ type: type,
349
+ description: this.properties[key].item.description
350
+ };
351
+ this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
352
+ }
295
353
  }
296
354
  else {
297
355
  this.throwInputError("ARRAY_01", [key], value);
@@ -454,37 +512,7 @@ class RequestType extends ReqResType_1.default {
454
512
  break;
455
513
  case 'enum':
456
514
  case 'enum?':
457
- const toEnumValue = [];
458
- for (const value of [...values]) {
459
- console.log(values, value);
460
- switch (property.item.enumType) {
461
- case 'number':
462
- case 'number?':
463
- console.log(this.isNumber(value));
464
- if (this.isNumber(value) === false) {
465
- this.throwInputError("NUMBER_31", [...keys, i], value);
466
- }
467
- toEnumValue.push(Number(value));
468
- break;
469
- case 'string':
470
- case 'string?':
471
- switch (typeof value) {
472
- case 'number':
473
- toEnumValue.push(value.toString());
474
- break;
475
- case 'string':
476
- toEnumValue.push(value);
477
- break;
478
- default:
479
- this.throwInputError("STRING_31", [...keys, i], value);
480
- }
481
- break;
482
- }
483
- if (Object.keys(property.item.enums).includes(value.toString()) === false) {
484
- this.throwInputError("ENUM_32", [...keys, i], value);
485
- }
486
- }
487
- this.changeBody([...keys, i], toEnumValue);
515
+ this.setEnum([...keys, i], values[i]);
488
516
  break;
489
517
  case 'map':
490
518
  case 'map?':
@@ -683,7 +711,7 @@ class RequestType extends ReqResType_1.default {
683
711
  * 指定された型に基づいて入力値を変換します。
684
712
  * 型変換に失敗した場合は例外をスローします。
685
713
  *
686
- * @param {string} type - The type to convert to (e.g., 'number', 'boolean', 'string', 'date', 'time', 'datetime')
714
+ * @param {string} property - The type to convert to (e.g., 'number', 'boolean', 'string', 'date', 'time', 'datetime')
687
715
  * 変換する型(例: 'number', 'boolean', 'string', 'date', 'time', 'datetime')
688
716
  * @param {any} value - The value to convert
689
717
  * 変換する値
@@ -692,14 +720,21 @@ class RequestType extends ReqResType_1.default {
692
720
  * @returns {any} The converted value, 変換された値
693
721
  * @throws {InputErrorException} Thrown if type conversion fails, 型変換に失敗した場合にスローされます
694
722
  */
695
- convertValue(type, value, keys, isRequestBody) {
696
- switch (type) {
723
+ convertValue(property, value, keys, isRequestBody) {
724
+ switch (property.type) {
697
725
  case 'number':
698
726
  case 'number?':
699
727
  if (this.isNumber(value) === false) {
700
728
  this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
701
729
  }
702
- return Number(value);
730
+ const numberValue = Number(value);
731
+ if (property.min !== undefined && numberValue < property.min) {
732
+ this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
733
+ }
734
+ if (property.max !== undefined && numberValue > property.max) {
735
+ this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
736
+ }
737
+ return numberValue;
703
738
  case 'boolean':
704
739
  case 'boolean?':
705
740
  switch (typeof value) {
@@ -720,14 +755,21 @@ class RequestType extends ReqResType_1.default {
720
755
  }
721
756
  case 'string':
722
757
  case 'string?':
758
+ let stringValue = "";
723
759
  switch (typeof value) {
724
760
  case 'number':
725
- return value.toString();
761
+ stringValue = value.toString();
762
+ break;
726
763
  case 'string':
727
- return value;
764
+ stringValue = value;
765
+ break;
728
766
  default:
729
767
  this.throwInputError(isRequestBody ? "STRING_21" : "STRING_91", keys, value);
730
768
  }
769
+ if (property.maxLength !== undefined && stringValue.length > property.maxLength) {
770
+ this.throwInputError(isRequestBody ? "STRING_22" : "STRING_92", keys, value);
771
+ }
772
+ return stringValue;
731
773
  case 'uuid':
732
774
  case 'uuid?':
733
775
  if (StringUtil_1.default.isUUID(value)) {
@@ -796,7 +838,7 @@ class RequestType extends ReqResType_1.default {
796
838
  */
797
839
  convertInput(keys, value) {
798
840
  const property = this.getProperty(keys);
799
- this.changeBody(keys, this.convertValue(property.type, value, keys, true));
841
+ this.changeBody(keys, this.convertValue(property, value, keys, true));
800
842
  }
801
843
  // ****************************************************************************
802
844
  // for create swagger
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.87",
3
+ "version": "2.0.89",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -1,11 +1,22 @@
1
1
  type PrimitiveKeyType =
2
- 'string' | 'number' | 'boolean' | 'date' | 'datetime' | 'time' | 'uuid' | 'mail' | 'https' | 'base64' |
3
- 'string?' | 'number?' | 'boolean?' | 'date?' | 'datetime?' | 'time?' | 'uuid?' | 'mail?' | 'https?' | 'base64?';
2
+ 'boolean' | 'date' | 'datetime' | 'time' | 'uuid' | 'mail' | 'https' | 'base64' |
3
+ 'boolean?' | 'date?' | 'datetime?' | 'time?' | 'uuid?' | 'mail?' | 'https?' | 'base64?';
4
4
 
5
5
  export type PrimitiveType = {
6
6
  type: PrimitiveKeyType;
7
7
  description?: string;
8
8
  };
9
+ export type StringType = {
10
+ type: 'string' | 'string?';
11
+ description?: string;
12
+ maxLength?: number;
13
+ };
14
+ export type NumberType = {
15
+ type: 'number' | 'number?';
16
+ description?: string;
17
+ max?: number;
18
+ min?: number;
19
+ };
9
20
  export type ObjectType = {
10
21
  type: 'object' | 'object?';
11
22
  description?: string;
@@ -30,7 +41,7 @@ export type EnumType = {
30
41
  enums: {[key: string | number]: string};
31
42
  };
32
43
 
33
- export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType | MapType;
44
+ export type PropertyType = PrimitiveType | StringType | NumberType | ObjectType | ArrayType | EnumType | MapType;
34
45
 
35
46
  export default class ReqResType {
36
47
 
@@ -1,5 +1,5 @@
1
1
  import { Request } from 'express';
2
- import ReqResType, { EnumType, PrimitiveType } from "./ReqResType";
2
+ import ReqResType, { EnumType, PrimitiveType, PropertyType, StringType } from "./ReqResType";
3
3
  import { InputErrorException } from '../exceptions/Exception';
4
4
  import StringUtil from '../Utils/StringUtil';
5
5
  import { ValidateStringUtil } from 'type-utils-n-daira';
@@ -11,8 +11,11 @@ export interface ErrorMessageType {
11
11
  INVALID_OBJECT: string;
12
12
  INVALID_ARRAY: string;
13
13
  INVALID_NUMBER: string;
14
+ INVALID_NUMBER_MIN: string;
15
+ INVALID_NUMBER_MAX: string;
14
16
  INVALID_BOOL: string;
15
17
  INVALID_STRING: string;
18
+ INVALID_STRING_MAX_LENGTH: string;
16
19
  INVALID_UUID: string;
17
20
  INVALID_MAIL: string;
18
21
  INVALID_HTTPS: string;
@@ -40,8 +43,11 @@ export class RequestType extends ReqResType {
40
43
  INVALID_OBJECT: '{property} must be of type Object. ({value})',
41
44
  INVALID_ARRAY: '{property} must be of type Array. ({value})',
42
45
  INVALID_NUMBER: '{property} must be of type number. ({value})',
46
+ INVALID_NUMBER_MAX: '{property} must be less than or equal to {max}. ({value})',
47
+ INVALID_NUMBER_MIN: '{property} must be greater than or equal to {min}. ({value})',
43
48
  INVALID_BOOL: '{property} must be of type bool or a string with true, false, or a number with 0, 1. ({value})',
44
49
  INVALID_STRING: '{property} must be of type string. ({value})',
50
+ INVALID_STRING_MAX_LENGTH: '{property} must be less than or equal to {maxLength} characters. ({value})',
45
51
  INVALID_UUID: '{property} must be a UUID. ({value})',
46
52
  INVALID_MAIL: '{property} must be an email. ({value})',
47
53
  INVALID_HTTPS: '{property} must be an https or http URL. ({value})',
@@ -60,8 +66,11 @@ export class RequestType extends ReqResType {
60
66
  INVALID_OBJECT: '{property}はobject型で入力してください。({value})',
61
67
  INVALID_ARRAY: '{property}はarray型で入力してください。({value})',
62
68
  INVALID_NUMBER: '{property}はnumber型または半角数値のstring型で入力してください。({value})',
69
+ INVALID_NUMBER_MAX: '{property}は{max}以下の値で入力してください。({value})',
70
+ INVALID_NUMBER_MIN: '{property}は{min}以上の値で入力してください。({value})',
63
71
  INVALID_BOOL: '{property}はboolean型またはtrue、falseのstring型または0、1のnumber型で入力してください。({value})',
64
72
  INVALID_STRING: '{property}はstring型で入力してください。({value})',
73
+ INVALID_STRING_MAX_LENGTH: '{property}は{maxLength}文字以内で入力してください。({value})',
65
74
  INVALID_UUID: '{property}はUUID形式のstring型で入力してください。({value})',
66
75
  INVALID_MAIL: '{property}はメールアドレス形式のstring型で入力してください。({value})',
67
76
  INVALID_HTTPS: '{property}はhttpsまたはhttpのURL形式のstring型で入力してください。({value})',
@@ -123,7 +132,7 @@ export class RequestType extends ReqResType {
123
132
  throw new Error(`${key} is not set in paramProperties.`);
124
133
  }
125
134
  const property = this.paramProperties[index];
126
- this.params[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${index})`], false);
135
+ this.params[key] = this.convertValue(property, value, [key, `(pathIndex: ${index})`], false);
127
136
  }
128
137
  }
129
138
  this.params = request.params ?? {};
@@ -143,13 +152,13 @@ export class RequestType extends ReqResType {
143
152
  private throwInputError(code:
144
153
  "REQUIRE_00" | "REQUIRE_01" | "OBJECT_01" | "ARRAY_01" | "UNNECESSARY_01" |
145
154
  "REQUIRE_11" | "OBJECT_11" | "ARRAY_11" | "UNNECESSARY_11" |
146
- "NUMBER_21" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
155
+ "NUMBER_21" | "NUMBER_22" | "NUMBER_23" | "BOOL_21" | "BOOL_22" | "BOOL_23" | "STRING_21" | "STRING_22" | "UUID_21" | "MAIL_21" | "DATE_21" | "DATE_22" |
147
156
  "TIME_21" | "DATETIME_21" | "DATETIME_22" | "HTTPS_21" | "BASE64_21" |
148
157
  "REQUIRE_31" |
149
- "ENUM_32" | "NUMBER_31" | "STRING_31" | "ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
158
+ "ENUM_32" | "ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
150
159
  "MAP_01" | "MAP_02" | "MAP_03" | "MAP_04" | "MAP_05" | "MAP_11" | "MAP_12" | "MAP_13" | "MAP_14" | "MAP_15" |
151
160
  "MAP_31" | "MAP_32" | "MAP_33" | "MAP_34" | "MAP_35" |
152
- "NUMBER_91" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
161
+ "NUMBER_91" | "NUMBER_92" | "NUMBER_93" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "STRING_92" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
153
162
  "TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
154
163
  , keys: Array<string | number>, value: any): never {
155
164
  const list = {
@@ -163,10 +172,13 @@ export class RequestType extends ReqResType {
163
172
  "ARRAY_11": this.ERROR_MESSAGE.INVALID_ARRAY,
164
173
  "UNNECESSARY_11": this.ERROR_MESSAGE.UNNECESSARY,
165
174
  "NUMBER_21": this.ERROR_MESSAGE.INVALID_NUMBER,
175
+ "NUMBER_22": this.ERROR_MESSAGE.INVALID_NUMBER_MIN,
176
+ "NUMBER_23": this.ERROR_MESSAGE.INVALID_NUMBER_MAX,
166
177
  "BOOL_21": this.ERROR_MESSAGE.INVALID_BOOL,
167
178
  "BOOL_22": this.ERROR_MESSAGE.INVALID_BOOL,
168
179
  "BOOL_23": this.ERROR_MESSAGE.INVALID_BOOL,
169
180
  "STRING_21": this.ERROR_MESSAGE.INVALID_STRING,
181
+ "STRING_22": this.ERROR_MESSAGE.INVALID_STRING_MAX_LENGTH,
170
182
  "UUID_21": this.ERROR_MESSAGE.INVALID_UUID,
171
183
  "MAIL_21": this.ERROR_MESSAGE.INVALID_MAIL,
172
184
  "DATE_21": this.ERROR_MESSAGE.INVALID_DATE,
@@ -177,8 +189,6 @@ export class RequestType extends ReqResType {
177
189
  "HTTPS_21": this.ERROR_MESSAGE.INVALID_HTTPS,
178
190
  "BASE64_21": this.ERROR_MESSAGE.INVALID_BASE64,
179
191
  "REQUIRE_31": this.ERROR_MESSAGE.REQUIRED,
180
- "NUMBER_31": this.ERROR_MESSAGE.INVALID_NUMBER,
181
- "STRING_31": this.ERROR_MESSAGE.INVALID_STRING,
182
192
  "ENUM_32": this.ERROR_MESSAGE.INVALID_ENUM,
183
193
  "NUMBER_41": this.ERROR_MESSAGE.INVALID_NUMBER,
184
194
  "STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
@@ -200,10 +210,13 @@ export class RequestType extends ReqResType {
200
210
  "MAP_34": this.ERROR_MESSAGE.INVALID_MAP_BOOL,
201
211
  "MAP_35": this.ERROR_MESSAGE.INVALID_MAP_BOOL,
202
212
  "NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
213
+ "NUMBER_92": this.ERROR_MESSAGE.INVALID_NUMBER_MIN,
214
+ "NUMBER_93": this.ERROR_MESSAGE.INVALID_NUMBER_MAX,
203
215
  "BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
204
216
  "BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
205
217
  "BOOL_93": this.ERROR_MESSAGE.INVALID_BOOL,
206
218
  "STRING_91": this.ERROR_MESSAGE.INVALID_STRING,
219
+ "STRING_92": this.ERROR_MESSAGE.INVALID_STRING_MAX_LENGTH,
207
220
  "UUID_91": this.ERROR_MESSAGE.INVALID_UUID,
208
221
  "MAIL_91": this.ERROR_MESSAGE.INVALID_MAIL,
209
222
  "DATE_91": this.ERROR_MESSAGE.INVALID_DATE,
@@ -216,9 +229,21 @@ export class RequestType extends ReqResType {
216
229
  }
217
230
 
218
231
  let errorMessage = list[code];
219
- if (code === "ENUM_32" || code === "ENUM_41" || code === "ENUM_42") {
220
- const property = this.getProperty(keys) as EnumType;
221
- errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums ?? '').join(','));
232
+ const property = this.getProperty(keys);
233
+ switch (property.type) {
234
+ case 'enum':
235
+ case 'enum?':
236
+ errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums ?? '').join(','));
237
+ break;
238
+ case 'string':
239
+ case 'string?':
240
+ errorMessage = errorMessage.replace('{maxLength}', Object.keys(property.maxLength ?? '').join(','));
241
+ break;
242
+ case 'number':
243
+ case 'number?':
244
+ errorMessage = errorMessage.replace('{max}', Object.keys(property.max ?? '').join(','));
245
+ errorMessage = errorMessage.replace('{min}', Object.keys(property.min ?? '').join(','));
246
+ break;
222
247
  }
223
248
 
224
249
  errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
@@ -303,7 +328,42 @@ export class RequestType extends ReqResType {
303
328
  if (request.method === 'GET' || request.method === 'DELETE') {
304
329
  // GET,DELETEメソッドの場合、?array=1&array=2で配列となるが、
305
330
  // ?array=1のみで終わる場合は配列にならないため、直接配列にしている
306
- this.data[key] = [this.convertValue(this.properties[key].item.type, value, [key, 0], true)];
331
+ const type = this.properties[key].item.type;
332
+ if (type === 'object' || type === 'object?' || type === 'array' || type === 'array?' || type === 'map' || type === 'map?') {
333
+ throw new Error("GETまたはDELETEメソッドでは配列型にobject, array, mapを使用することはできません。");
334
+ }
335
+
336
+ if (type === 'enum' || type === 'enum?') {
337
+ const tempProp = {
338
+ type: type,
339
+ description: this.properties[key].item.description,
340
+ enumType: this.properties[key].item.enumType,
341
+ enums: this.properties[key].item.enums,
342
+ };
343
+ this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
344
+ } else if (type === 'string' || type === 'string?') {
345
+ const tempProp = {
346
+ type: type,
347
+ description: this.properties[key].item.description,
348
+ maxLength: this.properties[key].item.maxLength,
349
+ };
350
+ this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
351
+ } else if (type === 'number' || type === 'number?') {
352
+ const tempProp = {
353
+ type: type,
354
+ description: this.properties[key].item.description,
355
+ max: this.properties[key].item.max,
356
+ min: this.properties[key].item.min,
357
+ };
358
+ this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
359
+ } else {
360
+ const tempProp = {
361
+ type: type,
362
+ description: this.properties[key].item.description
363
+ };
364
+ this.data[key] = [this.convertValue(tempProp, value, [key, 0], true)];
365
+ }
366
+
307
367
  } else {
308
368
  this.throwInputError("ARRAY_01", [key], value);
309
369
  }
@@ -474,38 +534,7 @@ export class RequestType extends ReqResType {
474
534
  break;
475
535
  case 'enum':
476
536
  case 'enum?':
477
- const toEnumValue = [];
478
- for (const value of [...values]) {
479
- console.log(values, value)
480
- switch (property.item.enumType) {
481
- case 'number':
482
- case 'number?':
483
- console.log(this.isNumber(value));
484
- if (this.isNumber(value) === false) {
485
- this.throwInputError("NUMBER_31", [...keys, i], value);
486
- }
487
- toEnumValue.push(Number(value));
488
- break;
489
- case 'string':
490
- case 'string?':
491
- switch (typeof value) {
492
- case 'number':
493
- toEnumValue.push(value.toString());
494
- break;
495
- case 'string':
496
- toEnumValue.push(value);
497
- break;
498
- default:
499
- this.throwInputError("STRING_31", [...keys, i], value);
500
- }
501
- break;
502
- }
503
-
504
- if (Object.keys(property.item.enums).includes(value.toString()) === false) {
505
- this.throwInputError("ENUM_32", [...keys, i], value);
506
- }
507
- }
508
- this.changeBody([...keys, i], toEnumValue);
537
+ this.setEnum([...keys, i], values[i]);
509
538
  break;
510
539
  case 'map':
511
540
  case 'map?':
@@ -711,7 +740,7 @@ export class RequestType extends ReqResType {
711
740
  * 指定された型に基づいて入力値を変換します。
712
741
  * 型変換に失敗した場合は例外をスローします。
713
742
  *
714
- * @param {string} type - The type to convert to (e.g., 'number', 'boolean', 'string', 'date', 'time', 'datetime')
743
+ * @param {string} property - The type to convert to (e.g., 'number', 'boolean', 'string', 'date', 'time', 'datetime')
715
744
  * 変換する型(例: 'number', 'boolean', 'string', 'date', 'time', 'datetime')
716
745
  * @param {any} value - The value to convert
717
746
  * 変換する値
@@ -720,15 +749,23 @@ export class RequestType extends ReqResType {
720
749
  * @returns {any} The converted value, 変換された値
721
750
  * @throws {InputErrorException} Thrown if type conversion fails, 型変換に失敗した場合にスローされます
722
751
  */
723
- private convertValue(type: string, value: any, keys: Array<string | number>, isRequestBody: boolean) {
752
+ private convertValue(property: PropertyType, value: any, keys: Array<string | number>, isRequestBody: boolean) {
724
753
 
725
- switch (type) {
754
+ switch (property.type) {
726
755
  case 'number':
727
756
  case 'number?':
728
757
  if (this.isNumber(value) === false) {
729
758
  this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
730
759
  }
731
- return Number(value);
760
+ const numberValue = Number(value);
761
+ if (property.min !== undefined && numberValue < property.min) {
762
+ this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
763
+ }
764
+
765
+ if (property.max !== undefined && numberValue > property.max) {
766
+ this.throwInputError(isRequestBody ? "NUMBER_21" : "NUMBER_91", keys, value);
767
+ }
768
+ return numberValue;
732
769
  case 'boolean':
733
770
  case 'boolean?':
734
771
  switch (typeof value) {
@@ -749,14 +786,22 @@ export class RequestType extends ReqResType {
749
786
  }
750
787
  case 'string':
751
788
  case 'string?':
789
+ let stringValue: string = "";
752
790
  switch (typeof value) {
753
791
  case 'number':
754
- return value.toString();
792
+ stringValue = value.toString();
793
+ break;
755
794
  case 'string':
756
- return value;
795
+ stringValue = value;
796
+ break;
757
797
  default:
758
798
  this.throwInputError(isRequestBody ? "STRING_21" : "STRING_91", keys, value);
759
799
  }
800
+
801
+ if (property.maxLength !== undefined && stringValue.length > property.maxLength) {
802
+ this.throwInputError(isRequestBody ? "STRING_22" : "STRING_92", keys, value);
803
+ }
804
+ return stringValue;
760
805
  case 'uuid':
761
806
  case 'uuid?':
762
807
  if (StringUtil.isUUID(value)) {
@@ -830,7 +875,7 @@ export class RequestType extends ReqResType {
830
875
  */
831
876
  private convertInput(keys: Array<string | number>, value: any) {
832
877
  const property = this.getProperty(keys);
833
- this.changeBody(keys, this.convertValue(property.type, value, keys, true));
878
+ this.changeBody(keys, this.convertValue(property, value, keys, true));
834
879
  }
835
880
 
836
881