pg-mvc-service 2.0.52 → 2.0.54
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/reqestResponse/ReqResType.js +68 -0
- package/dist/reqestResponse/RequestType.js +28 -37
- package/dist/reqestResponse/ResponseType.js +46 -55
- package/package.json +1 -1
- package/src/reqestResponse/ReqResType.ts +75 -0
- package/src/reqestResponse/RequestType.ts +29 -42
- package/src/reqestResponse/ResponseType.ts +52 -61
|
@@ -4,6 +4,74 @@ class ReqResType {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
this.properties = {};
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Retrieve the property definition corresponding to the specified key path.
|
|
9
|
+
* 指定されたキーパスに対応するプロパティ定義を取得します。
|
|
10
|
+
* @param {Array<string | number>} keys - Access path to the property (array of strings or index numbers)
|
|
11
|
+
* プロパティへのアクセスパス(文字列またはインデックス番号の配列)
|
|
12
|
+
* @returns {BaseType} Property definition object
|
|
13
|
+
* プロパティ定義オブジェクト
|
|
14
|
+
*/
|
|
15
|
+
// protected getProperty(keys: Array<string | number>) {
|
|
16
|
+
// let property: any = this.properties;
|
|
17
|
+
// for (let i = 0;i < keys.length;i++) {
|
|
18
|
+
// const key = keys[i];
|
|
19
|
+
// if (typeof key === 'number') {
|
|
20
|
+
// property = property.properties;
|
|
21
|
+
// continue;
|
|
22
|
+
// }
|
|
23
|
+
// if (i === 0) {
|
|
24
|
+
// property = property[key];
|
|
25
|
+
// } else {
|
|
26
|
+
// property = property.properties[key];
|
|
27
|
+
// }
|
|
28
|
+
// }
|
|
29
|
+
// return property;
|
|
30
|
+
// }
|
|
31
|
+
/**
|
|
32
|
+
* Retrieve property type data
|
|
33
|
+
* プロパティ型のデータを取得
|
|
34
|
+
* @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
35
|
+
* @returns {any} Retrieved property data, 取得されたプロパティデータ
|
|
36
|
+
*/
|
|
37
|
+
getProperty(keys) {
|
|
38
|
+
if (keys.length === 0) {
|
|
39
|
+
throw new Error(`getPropertyメソッドでは1以上のkeysからしか入力を受け付けない。`);
|
|
40
|
+
}
|
|
41
|
+
const firstKey = keys[0];
|
|
42
|
+
let property = this.properties[firstKey];
|
|
43
|
+
for (let i = 1; i < keys.length; i++) {
|
|
44
|
+
const key = keys[i];
|
|
45
|
+
if (typeof key === 'number') {
|
|
46
|
+
if (property.type === 'array' || property.type === 'array?') {
|
|
47
|
+
property = property.properties;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error(`getPropertyでnumber型のINPUTにも関わらず、array以外のtypeの場合のエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
switch (property.type) {
|
|
55
|
+
case 'array':
|
|
56
|
+
case 'array?':
|
|
57
|
+
if (typeof key !== 'number') {
|
|
58
|
+
throw new Error(`getPropertyでnumber型のINPUTで、array以外の場合はエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
59
|
+
}
|
|
60
|
+
property = property.properties;
|
|
61
|
+
continue;
|
|
62
|
+
case 'object':
|
|
63
|
+
case 'object':
|
|
64
|
+
if (typeof key !== 'string') {
|
|
65
|
+
throw new Error(`getPropertyでnumber型のINPUTで、arrayの場合はエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
66
|
+
}
|
|
67
|
+
property = property.properties[key];
|
|
68
|
+
continue;
|
|
69
|
+
default:
|
|
70
|
+
throw new Error(`getPropertyでarray,object以外のtypeを読み込もうとしている。\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return property;
|
|
74
|
+
}
|
|
7
75
|
/**
|
|
8
76
|
* Checks if the value is a valid date-time format
|
|
9
77
|
* 値が有効な日付時間形式かどうかを確認します
|
|
@@ -136,6 +136,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
136
136
|
* @returns {string} The generated error message. 生成されたエラーメッセージ
|
|
137
137
|
*/
|
|
138
138
|
throwInputError(code, keys, value) {
|
|
139
|
+
var _a;
|
|
139
140
|
const list = {
|
|
140
141
|
"REQUIRE_00": this.ERROR_MESSAGE.REQUIRED,
|
|
141
142
|
"REQUIRE_01": this.ERROR_MESSAGE.REQUIRED,
|
|
@@ -184,7 +185,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
184
185
|
let errorMessage = list[code];
|
|
185
186
|
if (code === "ENUM_41" || code === "ENUM_42") {
|
|
186
187
|
const property = this.getProperty(keys);
|
|
187
|
-
errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums).join(','));
|
|
188
|
+
errorMessage = errorMessage.replace('{enums}', Object.keys((_a = property.enums) !== null && _a !== void 0 ? _a : '').join(','));
|
|
188
189
|
}
|
|
189
190
|
errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
|
|
190
191
|
throw new Exception_1.InputErrorException(code, errorMessage);
|
|
@@ -307,6 +308,9 @@ class RequestType extends ReqResType_1.default {
|
|
|
307
308
|
*/
|
|
308
309
|
setEnum(keys, value) {
|
|
309
310
|
const property = this.getProperty(keys);
|
|
311
|
+
if (property.type !== 'enum' && property.type !== 'enum?') {
|
|
312
|
+
throw new Error(`setEnumメソッドでEnum型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
313
|
+
}
|
|
310
314
|
const enumType = property.enumType;
|
|
311
315
|
if (value === undefined || value === null || (typeof value === 'string' && value === '')) {
|
|
312
316
|
if (enumType.endsWith('?')) {
|
|
@@ -358,6 +362,9 @@ class RequestType extends ReqResType_1.default {
|
|
|
358
362
|
*/
|
|
359
363
|
setArray(keys, values) {
|
|
360
364
|
const property = this.getProperty(keys);
|
|
365
|
+
if (property.type !== 'array' && property.type !== 'array?') {
|
|
366
|
+
throw new Error(`setArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
367
|
+
}
|
|
361
368
|
for (let i = 0; i < values.length; i++) {
|
|
362
369
|
// NULL Check
|
|
363
370
|
if (values[i] === undefined || values[i] === null || (property.properties.type.replace("?", "") !== "string" && values[i] === "")) {
|
|
@@ -423,31 +430,6 @@ class RequestType extends ReqResType_1.default {
|
|
|
423
430
|
// }
|
|
424
431
|
// }
|
|
425
432
|
}
|
|
426
|
-
/**
|
|
427
|
-
* Retrieve the property definition corresponding to the specified key path.
|
|
428
|
-
* 指定されたキーパスに対応するプロパティ定義を取得します。
|
|
429
|
-
* @param {Array<string | number>} keys - Access path to the property (array of strings or index numbers)
|
|
430
|
-
* プロパティへのアクセスパス(文字列またはインデックス番号の配列)
|
|
431
|
-
* @returns {BaseType} Property definition object
|
|
432
|
-
* プロパティ定義オブジェクト
|
|
433
|
-
*/
|
|
434
|
-
getProperty(keys) {
|
|
435
|
-
let property = this.properties;
|
|
436
|
-
for (let i = 0; i < keys.length; i++) {
|
|
437
|
-
const key = keys[i];
|
|
438
|
-
if (typeof key === 'number') {
|
|
439
|
-
property = property.properties;
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
if (i === 0) {
|
|
443
|
-
property = property[key];
|
|
444
|
-
}
|
|
445
|
-
else {
|
|
446
|
-
property = property.properties[key];
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return property;
|
|
450
|
-
}
|
|
451
433
|
/**
|
|
452
434
|
* Set the value of the request body to the specified path.
|
|
453
435
|
* Automatically create intermediate objects or arrays as needed.
|
|
@@ -487,6 +469,9 @@ class RequestType extends ReqResType_1.default {
|
|
|
487
469
|
*/
|
|
488
470
|
setObject(keys, values) {
|
|
489
471
|
const property = this.getProperty(keys);
|
|
472
|
+
if (property.type !== 'object' && property.type !== 'object?') {
|
|
473
|
+
throw new Error(`setObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
474
|
+
}
|
|
490
475
|
for (const key of Object.keys(property.properties)) {
|
|
491
476
|
// NULL Check
|
|
492
477
|
if (key in values === false || values[key] === null || values[key] === "") {
|
|
@@ -764,12 +749,15 @@ class RequestType extends ReqResType_1.default {
|
|
|
764
749
|
* Swagger形式のプロパティ定義
|
|
765
750
|
*/
|
|
766
751
|
makeSwaggerProperyFromObject(keys, tabCount) {
|
|
767
|
-
var _a;
|
|
752
|
+
var _a, _b;
|
|
753
|
+
const objectProperty = this.getProperty(keys);
|
|
754
|
+
if (objectProperty.type !== 'object' && objectProperty.type !== 'object?') {
|
|
755
|
+
throw new Error(`setObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
756
|
+
}
|
|
768
757
|
const space = ' '.repeat(tabCount);
|
|
769
758
|
let ymlString = `${space}properties:\n`;
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
const property = properties[key];
|
|
759
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
760
|
+
const property = objectProperty.properties[key];
|
|
773
761
|
ymlString += `${space} ${key}:\n`;
|
|
774
762
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
775
763
|
const descJoin = `\n${space} `;
|
|
@@ -779,7 +767,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
779
767
|
ymlString += `${Object.entries(property.enums).map(([key, value]) => `${descJoin}- ${key}: ${value}`)}\n`;
|
|
780
768
|
}
|
|
781
769
|
else if (((_a = property.description) !== null && _a !== void 0 ? _a : '') !== '') {
|
|
782
|
-
ymlString += `${space} description: |${descJoin}${property.description.replaceAll('\n', descJoin)}\n`;
|
|
770
|
+
ymlString += `${space} description: |${descJoin}${((_b = property.description) !== null && _b !== void 0 ? _b : "").replaceAll('\n', descJoin)}\n`;
|
|
783
771
|
}
|
|
784
772
|
if (property.type === 'enum' || property.type === 'enum?') {
|
|
785
773
|
ymlString += `${space} nullable: ${property.enumType.endsWith('?')}\n`;
|
|
@@ -813,16 +801,19 @@ class RequestType extends ReqResType_1.default {
|
|
|
813
801
|
* Swagger形式のプロパティ定義
|
|
814
802
|
*/
|
|
815
803
|
makeSwaggerPropertyFromArray(keys, tabCount) {
|
|
816
|
-
var _a;
|
|
817
|
-
const
|
|
804
|
+
var _a, _b;
|
|
805
|
+
const arrayProperty = this.getProperty(keys);
|
|
806
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
807
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
808
|
+
}
|
|
818
809
|
const space = ' '.repeat(tabCount);
|
|
819
810
|
let ymlString = `${space}items:\n`;
|
|
820
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
821
|
-
if (((_a =
|
|
811
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
812
|
+
if (((_a = arrayProperty.properties.description) !== null && _a !== void 0 ? _a : '') !== '') {
|
|
822
813
|
const descJoin = `\n${space} `;
|
|
823
|
-
ymlString += `${space} description: |${descJoin}${
|
|
814
|
+
ymlString += `${space} description: |${descJoin}${((_b = arrayProperty.properties.description) !== null && _b !== void 0 ? _b : '').replaceAll('\n', descJoin)}\n`;
|
|
824
815
|
}
|
|
825
|
-
switch (
|
|
816
|
+
switch (arrayProperty.properties.type) {
|
|
826
817
|
case 'object':
|
|
827
818
|
case 'object?':
|
|
828
819
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
|
@@ -59,28 +59,33 @@ class ResponseType extends ReqResType_1.default {
|
|
|
59
59
|
getObject(keys) {
|
|
60
60
|
let resData = {};
|
|
61
61
|
const data = this.getData(keys);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
62
|
+
const objectProperty = this.getProperty(keys);
|
|
63
|
+
if (objectProperty.type !== 'object' && objectProperty.type !== 'object?') {
|
|
64
|
+
throw new Error(`getObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
65
|
+
}
|
|
66
|
+
for (const keys of Object.keys(objectProperty.properties)) {
|
|
67
|
+
for (const key of Object.keys(objectProperty)) {
|
|
68
|
+
if (key in data === false || data[key] === undefined) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const property = objectProperty.properties[key];
|
|
72
|
+
if (data[key] === null || (property.type.replace("?", "") !== "string" && data[key] === "")) {
|
|
73
|
+
resData[key] = property.type.endsWith('?') ? null : undefined;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
switch (property.type) {
|
|
77
|
+
case 'object':
|
|
78
|
+
case 'object?':
|
|
79
|
+
resData[key] = this.getObject([...keys, key]);
|
|
80
|
+
break;
|
|
81
|
+
case 'array':
|
|
82
|
+
case 'array?':
|
|
83
|
+
resData[key] = this.getArray([...keys, key]);
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
resData[key] = this.getValue([...keys, key]);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
return resData;
|
|
@@ -96,10 +101,13 @@ class ResponseType extends ReqResType_1.default {
|
|
|
96
101
|
if (data === undefined || Array.isArray(data) === false) {
|
|
97
102
|
return undefined;
|
|
98
103
|
}
|
|
99
|
-
const
|
|
104
|
+
const arrayProperty = this.getProperty(keys);
|
|
105
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
106
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
107
|
+
}
|
|
100
108
|
let resData = [];
|
|
101
109
|
for (let i = 0; i < data.length; i++) {
|
|
102
|
-
switch (properties.type) {
|
|
110
|
+
switch (arrayProperty.properties.type) {
|
|
103
111
|
case 'object':
|
|
104
112
|
case 'object?':
|
|
105
113
|
resData.push(this.getObject([...keys, i]));
|
|
@@ -115,29 +123,6 @@ class ResponseType extends ReqResType_1.default {
|
|
|
115
123
|
}
|
|
116
124
|
return resData;
|
|
117
125
|
}
|
|
118
|
-
/**
|
|
119
|
-
* Retrieve property type data
|
|
120
|
-
* プロパティ型のデータを取得
|
|
121
|
-
* @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
122
|
-
* @returns {any} Retrieved property data, 取得されたプロパティデータ
|
|
123
|
-
*/
|
|
124
|
-
getProperty(keys) {
|
|
125
|
-
let property = this.properties;
|
|
126
|
-
for (let i = 0; i < keys.length; i++) {
|
|
127
|
-
const key = keys[i];
|
|
128
|
-
if (typeof key === 'number') {
|
|
129
|
-
property = property.properties;
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
if (i === 0) {
|
|
133
|
-
property = property[key];
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
property = property.properties[key];
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return property;
|
|
140
|
-
}
|
|
141
126
|
/**
|
|
142
127
|
* Retrieve data based on the provided keys
|
|
143
128
|
* 指定されたキーに基づいてデータを取得
|
|
@@ -337,11 +322,14 @@ class ResponseType extends ReqResType_1.default {
|
|
|
337
322
|
* Swagger形式のプロパティ定義
|
|
338
323
|
*/
|
|
339
324
|
makeSwaggerProperyFromObject(keys, tabCount) {
|
|
325
|
+
const objectProperty = this.getProperty(keys);
|
|
326
|
+
if (objectProperty.type !== 'object' && objectProperty.type !== 'object?') {
|
|
327
|
+
throw new Error(`getObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
328
|
+
}
|
|
340
329
|
const space = ' '.repeat(tabCount);
|
|
341
330
|
let ymlString = `${space}properties:\n`;
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
const property = properties[key];
|
|
331
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
332
|
+
const property = objectProperty.properties[key];
|
|
345
333
|
ymlString += `${space} ${key}:\n`;
|
|
346
334
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
347
335
|
if (property.description !== undefined) {
|
|
@@ -372,15 +360,18 @@ class ResponseType extends ReqResType_1.default {
|
|
|
372
360
|
* @returns {string} Swagger format property definition, Swagger形式のプロパティ定義
|
|
373
361
|
*/
|
|
374
362
|
makeSwaggerPropertyFromArray(keys, tabCount) {
|
|
375
|
-
const
|
|
363
|
+
const arrayProperty = this.getProperty(keys);
|
|
364
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
365
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
366
|
+
}
|
|
376
367
|
const space = ' '.repeat(tabCount);
|
|
377
368
|
let ymlString = `${space}items:\n`;
|
|
378
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
379
|
-
if (
|
|
369
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
370
|
+
if (arrayProperty.properties.description !== undefined) {
|
|
380
371
|
const joinSpace = `\n${space} `;
|
|
381
|
-
ymlString += `${space} description: |${joinSpace}${
|
|
372
|
+
ymlString += `${space} description: |${joinSpace}${arrayProperty.properties.description.replaceAll("\n", joinSpace)}\n`;
|
|
382
373
|
}
|
|
383
|
-
switch (
|
|
374
|
+
switch (arrayProperty.properties.type) {
|
|
384
375
|
case 'object':
|
|
385
376
|
case 'object?':
|
|
386
377
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
package/package.json
CHANGED
|
@@ -36,6 +36,81 @@ export default class ReqResType {
|
|
|
36
36
|
|
|
37
37
|
protected properties: { [key: string]: PropertyType; } = {};
|
|
38
38
|
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Retrieve the property definition corresponding to the specified key path.
|
|
42
|
+
* 指定されたキーパスに対応するプロパティ定義を取得します。
|
|
43
|
+
* @param {Array<string | number>} keys - Access path to the property (array of strings or index numbers)
|
|
44
|
+
* プロパティへのアクセスパス(文字列またはインデックス番号の配列)
|
|
45
|
+
* @returns {BaseType} Property definition object
|
|
46
|
+
* プロパティ定義オブジェクト
|
|
47
|
+
*/
|
|
48
|
+
// protected getProperty(keys: Array<string | number>) {
|
|
49
|
+
// let property: any = this.properties;
|
|
50
|
+
// for (let i = 0;i < keys.length;i++) {
|
|
51
|
+
// const key = keys[i];
|
|
52
|
+
// if (typeof key === 'number') {
|
|
53
|
+
// property = property.properties;
|
|
54
|
+
// continue;
|
|
55
|
+
// }
|
|
56
|
+
|
|
57
|
+
// if (i === 0) {
|
|
58
|
+
// property = property[key];
|
|
59
|
+
// } else {
|
|
60
|
+
// property = property.properties[key];
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
// return property;
|
|
65
|
+
// }
|
|
66
|
+
/**
|
|
67
|
+
* Retrieve property type data
|
|
68
|
+
* プロパティ型のデータを取得
|
|
69
|
+
* @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
70
|
+
* @returns {any} Retrieved property data, 取得されたプロパティデータ
|
|
71
|
+
*/
|
|
72
|
+
protected getProperty(keys: Array<string | number>) {
|
|
73
|
+
if (keys.length === 0) {
|
|
74
|
+
throw new Error(`getPropertyメソッドでは1以上のkeysからしか入力を受け付けない。`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const firstKey = keys[0];
|
|
78
|
+
let property = this.properties[firstKey];
|
|
79
|
+
|
|
80
|
+
for (let i = 1;i < keys.length;i++) {
|
|
81
|
+
const key = keys[i];
|
|
82
|
+
if (typeof key === 'number') {
|
|
83
|
+
if (property.type === 'array' || property.type === 'array?') {
|
|
84
|
+
property = property.properties;
|
|
85
|
+
continue;
|
|
86
|
+
} else {
|
|
87
|
+
throw new Error(`getPropertyでnumber型のINPUTにも関わらず、array以外のtypeの場合のエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
switch (property.type) {
|
|
92
|
+
case 'array':
|
|
93
|
+
case 'array?':
|
|
94
|
+
if (typeof key !== 'number') {
|
|
95
|
+
throw new Error(`getPropertyでnumber型のINPUTで、array以外の場合はエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
96
|
+
}
|
|
97
|
+
property = property.properties;
|
|
98
|
+
continue;
|
|
99
|
+
case 'object':
|
|
100
|
+
case 'object':
|
|
101
|
+
if (typeof key !== 'string') {
|
|
102
|
+
throw new Error(`getPropertyでnumber型のINPUTで、arrayの場合はエラー\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
103
|
+
}
|
|
104
|
+
property = property.properties[key];
|
|
105
|
+
continue;
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(`getPropertyでarray,object以外のtypeを読み込もうとしている。\nキー一覧:${keys.join(',')} エラーキー:${key}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return property;
|
|
112
|
+
}
|
|
113
|
+
|
|
39
114
|
/**
|
|
40
115
|
* Checks if the value is a valid date-time format
|
|
41
116
|
* 値が有効な日付時間形式かどうかを確認します
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
-
import ReqResType, {
|
|
2
|
+
import ReqResType, { EnumType, PrimitiveType } 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';
|
|
@@ -193,8 +193,8 @@ export class RequestType extends ReqResType {
|
|
|
193
193
|
|
|
194
194
|
let errorMessage = list[code];
|
|
195
195
|
if (code === "ENUM_41" || code === "ENUM_42") {
|
|
196
|
-
const property = this.getProperty(keys);
|
|
197
|
-
errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums).join(','));
|
|
196
|
+
const property = this.getProperty(keys) as EnumType;
|
|
197
|
+
errorMessage = errorMessage.replace('{enums}', Object.keys(property.enums ?? '').join(','));
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
errorMessage = errorMessage.replace("{property}", keys.join('.')).replace("{value}", value);
|
|
@@ -318,6 +318,9 @@ export class RequestType extends ReqResType {
|
|
|
318
318
|
*/
|
|
319
319
|
private setEnum(keys: Array<string | number>, value: any) {
|
|
320
320
|
const property = this.getProperty(keys);
|
|
321
|
+
if (property.type !== 'enum' && property.type !== 'enum?') {
|
|
322
|
+
throw new Error(`setEnumメソッドでEnum型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
323
|
+
}
|
|
321
324
|
|
|
322
325
|
const enumType = property.enumType;
|
|
323
326
|
if (value === undefined || value === null || (typeof value === 'string' && value === '')) {
|
|
@@ -373,6 +376,10 @@ export class RequestType extends ReqResType {
|
|
|
373
376
|
*/
|
|
374
377
|
private setArray(keys: Array<string | number>, values: any) {
|
|
375
378
|
const property = this.getProperty(keys);
|
|
379
|
+
if (property.type !== 'array' && property.type !== 'array?') {
|
|
380
|
+
throw new Error(`setArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
381
|
+
}
|
|
382
|
+
|
|
376
383
|
for (let i = 0;i < values.length; i++) {
|
|
377
384
|
|
|
378
385
|
// NULL Check
|
|
@@ -443,33 +450,6 @@ export class RequestType extends ReqResType {
|
|
|
443
450
|
// }
|
|
444
451
|
}
|
|
445
452
|
|
|
446
|
-
/**
|
|
447
|
-
* Retrieve the property definition corresponding to the specified key path.
|
|
448
|
-
* 指定されたキーパスに対応するプロパティ定義を取得します。
|
|
449
|
-
* @param {Array<string | number>} keys - Access path to the property (array of strings or index numbers)
|
|
450
|
-
* プロパティへのアクセスパス(文字列またはインデックス番号の配列)
|
|
451
|
-
* @returns {BaseType} Property definition object
|
|
452
|
-
* プロパティ定義オブジェクト
|
|
453
|
-
*/
|
|
454
|
-
private getProperty(keys: Array<string | number>) {
|
|
455
|
-
let property: any = this.properties;
|
|
456
|
-
for (let i = 0;i < keys.length;i++) {
|
|
457
|
-
const key = keys[i];
|
|
458
|
-
if (typeof key === 'number') {
|
|
459
|
-
property = property.properties;
|
|
460
|
-
continue;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
if (i === 0) {
|
|
464
|
-
property = property[key];
|
|
465
|
-
} else {
|
|
466
|
-
property = property.properties[key];
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return property;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
453
|
/**
|
|
474
454
|
* Set the value of the request body to the specified path.
|
|
475
455
|
* Automatically create intermediate objects or arrays as needed.
|
|
@@ -511,6 +491,9 @@ export class RequestType extends ReqResType {
|
|
|
511
491
|
*/
|
|
512
492
|
private setObject(keys: Array<string | number>, values: {[key: string]: any}) {
|
|
513
493
|
const property = this.getProperty(keys);
|
|
494
|
+
if (property.type !== 'object' && property.type !== 'object?') {
|
|
495
|
+
throw new Error(`setObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
496
|
+
}
|
|
514
497
|
|
|
515
498
|
for (const key of Object.keys(property.properties)) {
|
|
516
499
|
|
|
@@ -811,15 +794,16 @@ export class RequestType extends ReqResType {
|
|
|
811
794
|
*/
|
|
812
795
|
private makeSwaggerProperyFromObject(keys: Array<string | number>, tabCount: number): string {
|
|
813
796
|
|
|
814
|
-
const
|
|
797
|
+
const objectProperty = this.getProperty(keys);
|
|
798
|
+
if (objectProperty.type !== 'object' && objectProperty.type !== 'object?') {
|
|
799
|
+
throw new Error(`setObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
800
|
+
}
|
|
815
801
|
|
|
802
|
+
const space = ' '.repeat(tabCount);
|
|
816
803
|
let ymlString = `${space}properties:\n`;
|
|
804
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
805
|
+
const property = objectProperty.properties[key];
|
|
817
806
|
|
|
818
|
-
const properties = this.getProperty(keys).properties;
|
|
819
|
-
for (const key of Object.keys(properties)) {
|
|
820
|
-
const property = properties[key];
|
|
821
|
-
|
|
822
|
-
|
|
823
807
|
ymlString += `${space} ${key}:\n`;
|
|
824
808
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
825
809
|
const descJoin = `\n${space} `;
|
|
@@ -828,7 +812,7 @@ export class RequestType extends ReqResType {
|
|
|
828
812
|
ymlString += `${descJoin}enum list`;
|
|
829
813
|
ymlString += `${Object.entries(property.enums).map(([key, value]) => `${descJoin}- ${key}: ${value}`)}\n`;
|
|
830
814
|
} else if ((property.description ?? '') !== '') {
|
|
831
|
-
ymlString += `${space} description: |${descJoin}${property.description.replaceAll('\n', descJoin)}\n`;
|
|
815
|
+
ymlString += `${space} description: |${descJoin}${(property.description ?? "").replaceAll('\n', descJoin)}\n`;
|
|
832
816
|
}
|
|
833
817
|
|
|
834
818
|
if (property.type === 'enum' || property.type === 'enum?') {
|
|
@@ -867,19 +851,22 @@ export class RequestType extends ReqResType {
|
|
|
867
851
|
*/
|
|
868
852
|
private makeSwaggerPropertyFromArray(keys: Array<string | number>, tabCount: number): string {
|
|
869
853
|
|
|
870
|
-
const
|
|
854
|
+
const arrayProperty = this.getProperty(keys);
|
|
855
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
856
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
857
|
+
}
|
|
871
858
|
|
|
872
859
|
const space = ' '.repeat(tabCount);
|
|
873
860
|
|
|
874
861
|
let ymlString = `${space}items:\n`;
|
|
875
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
876
|
-
if ((
|
|
862
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
863
|
+
if ((arrayProperty.properties.description ?? '') !== '') {
|
|
877
864
|
const descJoin = `\n${space} `;
|
|
878
|
-
ymlString += `${space} description: |${descJoin}${
|
|
865
|
+
ymlString += `${space} description: |${descJoin}${(arrayProperty.properties.description ?? '').replaceAll('\n', descJoin)}\n`;
|
|
879
866
|
}
|
|
880
867
|
|
|
881
868
|
|
|
882
|
-
switch (
|
|
869
|
+
switch (arrayProperty.properties.type) {
|
|
883
870
|
case 'object':
|
|
884
871
|
case 'object?':
|
|
885
872
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValidateStringUtil } from "type-utils-n-daira";
|
|
2
2
|
import StringUtil from "../Utils/StringUtil";
|
|
3
|
-
import ReqResType, {
|
|
3
|
+
import ReqResType, { PropertyType } from "./ReqResType";
|
|
4
4
|
|
|
5
5
|
export class ResponseType extends ReqResType {
|
|
6
6
|
|
|
@@ -60,30 +60,36 @@ export class ResponseType extends ReqResType {
|
|
|
60
60
|
let resData: {[key: string]: any} = {};
|
|
61
61
|
const data = this.getData(keys);
|
|
62
62
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const property = properties[key];
|
|
70
|
-
if (data[key] === null || (property.type.replace("?", "") !== "string" && data[key] === "")) {
|
|
71
|
-
resData[key] = property.type.endsWith('?') ? null : undefined;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
63
|
+
const objectProperty = this.getProperty(keys);
|
|
64
|
+
if (objectProperty.type !== 'object' && objectProperty.type !== 'object?') {
|
|
65
|
+
throw new Error(`getObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
66
|
+
}
|
|
74
67
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
68
|
+
for (const keys of Object.keys(objectProperty.properties)) {
|
|
69
|
+
for (const key of Object.keys(objectProperty)) {
|
|
70
|
+
if (key in data === false || data[key] === undefined) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const property = objectProperty.properties[key];
|
|
75
|
+
if (data[key] === null || (property.type.replace("?", "") !== "string" && data[key] === "")) {
|
|
76
|
+
resData[key] = property.type.endsWith('?') ? null : undefined;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
switch (property.type) {
|
|
81
|
+
case 'object':
|
|
82
|
+
case 'object?':
|
|
83
|
+
resData[key] = this.getObject([...keys, key]);
|
|
84
|
+
break;
|
|
85
|
+
case 'array':
|
|
86
|
+
case 'array?':
|
|
87
|
+
resData[key] = this.getArray([...keys, key]);
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
resData[key] = this.getValue([...keys, key]);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
95
|
|
|
@@ -103,10 +109,14 @@ export class ResponseType extends ReqResType {
|
|
|
103
109
|
return undefined;
|
|
104
110
|
}
|
|
105
111
|
|
|
106
|
-
const
|
|
112
|
+
const arrayProperty = this.getProperty(keys);
|
|
113
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
114
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
107
117
|
let resData: Array<any> = [];
|
|
108
118
|
for (let i = 0;i < data.length; i++) {
|
|
109
|
-
switch (properties.type) {
|
|
119
|
+
switch (arrayProperty.properties.type) {
|
|
110
120
|
case 'object':
|
|
111
121
|
case 'object?':
|
|
112
122
|
resData.push(this.getObject([...keys, i]));
|
|
@@ -124,31 +134,6 @@ export class ResponseType extends ReqResType {
|
|
|
124
134
|
return resData;
|
|
125
135
|
}
|
|
126
136
|
|
|
127
|
-
/**
|
|
128
|
-
* Retrieve property type data
|
|
129
|
-
* プロパティ型のデータを取得
|
|
130
|
-
* @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
131
|
-
* @returns {any} Retrieved property data, 取得されたプロパティデータ
|
|
132
|
-
*/
|
|
133
|
-
private getProperty(keys: Array<string | number>) {
|
|
134
|
-
let property: any = this.properties;
|
|
135
|
-
for (let i = 0;i < keys.length;i++) {
|
|
136
|
-
const key = keys[i];
|
|
137
|
-
if (typeof key === 'number') {
|
|
138
|
-
property = property.properties;
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (i === 0) {
|
|
143
|
-
property = property[key];
|
|
144
|
-
} else {
|
|
145
|
-
property = property.properties[key];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return property;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
137
|
/**
|
|
153
138
|
* Retrieve data based on the provided keys
|
|
154
139
|
* 指定されたキーに基づいてデータを取得
|
|
@@ -369,12 +354,15 @@ export class ResponseType extends ReqResType {
|
|
|
369
354
|
*/
|
|
370
355
|
private makeSwaggerProperyFromObject(keys: Array<string | number>, tabCount: number): string {
|
|
371
356
|
|
|
357
|
+
const objectProperty = this.getProperty(keys);
|
|
358
|
+
if (objectProperty.type !== 'object' && objectProperty.type !== 'object?') {
|
|
359
|
+
throw new Error(`getObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
360
|
+
}
|
|
361
|
+
|
|
372
362
|
const space = ' '.repeat(tabCount);
|
|
373
363
|
let ymlString = `${space}properties:\n`;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
for (const key of Object.keys(properties)) {
|
|
377
|
-
const property = properties[key];
|
|
364
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
365
|
+
const property = objectProperty.properties[key];
|
|
378
366
|
|
|
379
367
|
ymlString += `${space} ${key}:\n`;
|
|
380
368
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
@@ -409,16 +397,19 @@ export class ResponseType extends ReqResType {
|
|
|
409
397
|
*/
|
|
410
398
|
private makeSwaggerPropertyFromArray(keys: Array<string | number>, tabCount: number): string {
|
|
411
399
|
|
|
412
|
-
const
|
|
413
|
-
|
|
400
|
+
const arrayProperty = this.getProperty(keys);
|
|
401
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
402
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
403
|
+
}
|
|
414
404
|
|
|
405
|
+
const space = ' '.repeat(tabCount);
|
|
415
406
|
let ymlString = `${space}items:\n`;
|
|
416
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
417
|
-
if (
|
|
407
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
408
|
+
if (arrayProperty.properties.description !== undefined) {
|
|
418
409
|
const joinSpace = `\n${space} `;
|
|
419
|
-
ymlString += `${space} description: |${joinSpace}${
|
|
410
|
+
ymlString += `${space} description: |${joinSpace}${arrayProperty.properties.description.replaceAll("\n", joinSpace)}\n`;
|
|
420
411
|
}
|
|
421
|
-
switch (
|
|
412
|
+
switch (arrayProperty.properties.type) {
|
|
422
413
|
case 'object':
|
|
423
414
|
case 'object?':
|
|
424
415
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|