pg-mvc-service 2.0.53 → 2.0.55
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 +52 -52
- package/dist/reqestResponse/RequestType.js +28 -12
- package/dist/reqestResponse/ResponseType.js +51 -33
- package/package.json +1 -1
- package/src/reqestResponse/ReqResType.ts +55 -55
- package/src/reqestResponse/RequestType.ts +28 -14
- package/src/reqestResponse/ResponseType.ts +56 -36
|
@@ -12,66 +12,66 @@ class ReqResType {
|
|
|
12
12
|
* @returns {BaseType} Property definition object
|
|
13
13
|
* プロパティ定義オブジェクト
|
|
14
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
|
+
*/
|
|
15
37
|
getProperty(keys) {
|
|
16
|
-
|
|
17
|
-
|
|
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++) {
|
|
18
44
|
const key = keys[i];
|
|
19
45
|
if (typeof key === 'number') {
|
|
20
|
-
property
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
}
|
|
25
53
|
}
|
|
26
|
-
|
|
27
|
-
|
|
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}`);
|
|
28
71
|
}
|
|
29
72
|
}
|
|
30
73
|
return property;
|
|
31
74
|
}
|
|
32
|
-
// /**
|
|
33
|
-
// * Retrieve property type data
|
|
34
|
-
// * プロパティ型のデータを取得
|
|
35
|
-
// * @param {Array.<string|number>} keys - Path to the property, プロパティへのパス
|
|
36
|
-
// * @returns {any} Retrieved property data, 取得されたプロパティデータ
|
|
37
|
-
// */
|
|
38
|
-
// private getProperty(keys: Array<string | number>) {
|
|
39
|
-
// if (keys.length === 0) {
|
|
40
|
-
// throw new Error(`getPropertyメソッドでは1以上のkeysからしか入力を受け付けない。`);
|
|
41
|
-
// }
|
|
42
|
-
// const firstKey = keys[0];
|
|
43
|
-
// let property = this.properties[firstKey];
|
|
44
|
-
// for (let i = 1;i < keys.length;i++) {
|
|
45
|
-
// const key = keys[i];
|
|
46
|
-
// if (typeof key === 'number') {
|
|
47
|
-
// if (property.type === 'array' || property.type === 'array?') {
|
|
48
|
-
// property = property.properties;
|
|
49
|
-
// continue;
|
|
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
|
-
// }
|
|
75
75
|
/**
|
|
76
76
|
* Checks if the value is a valid date-time format
|
|
77
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] === "")) {
|
|
@@ -462,6 +469,9 @@ class RequestType extends ReqResType_1.default {
|
|
|
462
469
|
*/
|
|
463
470
|
setObject(keys, values) {
|
|
464
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
|
+
}
|
|
465
475
|
for (const key of Object.keys(property.properties)) {
|
|
466
476
|
// NULL Check
|
|
467
477
|
if (key in values === false || values[key] === null || values[key] === "") {
|
|
@@ -739,12 +749,15 @@ class RequestType extends ReqResType_1.default {
|
|
|
739
749
|
* Swagger形式のプロパティ定義
|
|
740
750
|
*/
|
|
741
751
|
makeSwaggerProperyFromObject(keys, tabCount) {
|
|
742
|
-
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
|
+
}
|
|
743
757
|
const space = ' '.repeat(tabCount);
|
|
744
758
|
let ymlString = `${space}properties:\n`;
|
|
745
|
-
const
|
|
746
|
-
|
|
747
|
-
const property = properties[key];
|
|
759
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
760
|
+
const property = objectProperty.properties[key];
|
|
748
761
|
ymlString += `${space} ${key}:\n`;
|
|
749
762
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
750
763
|
const descJoin = `\n${space} `;
|
|
@@ -754,7 +767,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
754
767
|
ymlString += `${Object.entries(property.enums).map(([key, value]) => `${descJoin}- ${key}: ${value}`)}\n`;
|
|
755
768
|
}
|
|
756
769
|
else if (((_a = property.description) !== null && _a !== void 0 ? _a : '') !== '') {
|
|
757
|
-
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`;
|
|
758
771
|
}
|
|
759
772
|
if (property.type === 'enum' || property.type === 'enum?') {
|
|
760
773
|
ymlString += `${space} nullable: ${property.enumType.endsWith('?')}\n`;
|
|
@@ -788,16 +801,19 @@ class RequestType extends ReqResType_1.default {
|
|
|
788
801
|
* Swagger形式のプロパティ定義
|
|
789
802
|
*/
|
|
790
803
|
makeSwaggerPropertyFromArray(keys, tabCount) {
|
|
791
|
-
var _a;
|
|
792
|
-
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
|
+
}
|
|
793
809
|
const space = ' '.repeat(tabCount);
|
|
794
810
|
let ymlString = `${space}items:\n`;
|
|
795
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
796
|
-
if (((_a =
|
|
811
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
812
|
+
if (((_a = arrayProperty.properties.description) !== null && _a !== void 0 ? _a : '') !== '') {
|
|
797
813
|
const descJoin = `\n${space} `;
|
|
798
|
-
ymlString += `${space} description: |${descJoin}${
|
|
814
|
+
ymlString += `${space} description: |${descJoin}${((_b = arrayProperty.properties.description) !== null && _b !== void 0 ? _b : '').replaceAll('\n', descJoin)}\n`;
|
|
799
815
|
}
|
|
800
|
-
switch (
|
|
816
|
+
switch (arrayProperty.properties.type) {
|
|
801
817
|
case 'object':
|
|
802
818
|
case 'object?':
|
|
803
819
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
|
@@ -59,28 +59,35 @@ 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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
resData[key] =
|
|
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
|
+
console.log(objectProperty);
|
|
67
|
+
for (const keys of Object.keys(objectProperty.properties)) {
|
|
68
|
+
for (const key of Object.keys(objectProperty)) {
|
|
69
|
+
console.log(key);
|
|
70
|
+
if (key in data === false || data[key] === undefined) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const property = objectProperty.properties[key];
|
|
74
|
+
if (data[key] === null || (property.type.replace("?", "") !== "string" && data[key] === "")) {
|
|
75
|
+
resData[key] = property.type.endsWith('?') ? null : undefined;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
switch (property.type) {
|
|
79
|
+
case 'object':
|
|
80
|
+
case 'object?':
|
|
81
|
+
resData[key] = this.getObject([...keys, key]);
|
|
82
|
+
break;
|
|
83
|
+
case 'array':
|
|
84
|
+
case 'array?':
|
|
85
|
+
resData[key] = this.getArray([...keys, key]);
|
|
86
|
+
break;
|
|
87
|
+
default:
|
|
88
|
+
resData[key] = this.getValue([...keys, key]);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
93
|
return resData;
|
|
@@ -96,13 +103,18 @@ class ResponseType extends ReqResType_1.default {
|
|
|
96
103
|
if (data === undefined || Array.isArray(data) === false) {
|
|
97
104
|
return undefined;
|
|
98
105
|
}
|
|
99
|
-
const
|
|
106
|
+
const arrayProperty = this.getProperty(keys);
|
|
107
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
108
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
109
|
+
}
|
|
100
110
|
let resData = [];
|
|
101
111
|
for (let i = 0; i < data.length; i++) {
|
|
102
|
-
switch (properties.type) {
|
|
112
|
+
switch (arrayProperty.properties.type) {
|
|
103
113
|
case 'object':
|
|
104
114
|
case 'object?':
|
|
105
|
-
|
|
115
|
+
const value = this.getObject([...keys, i]);
|
|
116
|
+
console.log(value);
|
|
117
|
+
resData.push(value);
|
|
106
118
|
break;
|
|
107
119
|
case 'array':
|
|
108
120
|
case 'array?':
|
|
@@ -314,11 +326,14 @@ class ResponseType extends ReqResType_1.default {
|
|
|
314
326
|
* Swagger形式のプロパティ定義
|
|
315
327
|
*/
|
|
316
328
|
makeSwaggerProperyFromObject(keys, tabCount) {
|
|
329
|
+
const objectProperty = this.getProperty(keys);
|
|
330
|
+
if (objectProperty.type !== 'object' && objectProperty.type !== 'object?') {
|
|
331
|
+
throw new Error(`getObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
332
|
+
}
|
|
317
333
|
const space = ' '.repeat(tabCount);
|
|
318
334
|
let ymlString = `${space}properties:\n`;
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
const property = properties[key];
|
|
335
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
336
|
+
const property = objectProperty.properties[key];
|
|
322
337
|
ymlString += `${space} ${key}:\n`;
|
|
323
338
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
324
339
|
if (property.description !== undefined) {
|
|
@@ -349,15 +364,18 @@ class ResponseType extends ReqResType_1.default {
|
|
|
349
364
|
* @returns {string} Swagger format property definition, Swagger形式のプロパティ定義
|
|
350
365
|
*/
|
|
351
366
|
makeSwaggerPropertyFromArray(keys, tabCount) {
|
|
352
|
-
const
|
|
367
|
+
const arrayProperty = this.getProperty(keys);
|
|
368
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
369
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
370
|
+
}
|
|
353
371
|
const space = ' '.repeat(tabCount);
|
|
354
372
|
let ymlString = `${space}items:\n`;
|
|
355
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
356
|
-
if (
|
|
373
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
374
|
+
if (arrayProperty.properties.description !== undefined) {
|
|
357
375
|
const joinSpace = `\n${space} `;
|
|
358
|
-
ymlString += `${space} description: |${joinSpace}${
|
|
376
|
+
ymlString += `${space} description: |${joinSpace}${arrayProperty.properties.description.replaceAll("\n", joinSpace)}\n`;
|
|
359
377
|
}
|
|
360
|
-
switch (
|
|
378
|
+
switch (arrayProperty.properties.type) {
|
|
361
379
|
case 'object':
|
|
362
380
|
case 'object?':
|
|
363
381
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
package/package.json
CHANGED
|
@@ -45,71 +45,71 @@ export default class ReqResType {
|
|
|
45
45
|
* @returns {BaseType} Property definition object
|
|
46
46
|
* プロパティ定義オブジェクト
|
|
47
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
|
+
*/
|
|
48
72
|
protected getProperty(keys: Array<string | number>) {
|
|
49
|
-
|
|
50
|
-
|
|
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++) {
|
|
51
81
|
const key = keys[i];
|
|
52
82
|
if (typeof key === 'number') {
|
|
53
|
-
property
|
|
54
|
-
|
|
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
|
+
}
|
|
55
89
|
}
|
|
56
90
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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}`);
|
|
61
108
|
}
|
|
62
109
|
}
|
|
63
110
|
|
|
64
111
|
return property;
|
|
65
112
|
}
|
|
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
|
-
// private 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
113
|
|
|
114
114
|
/**
|
|
115
115
|
* Checks if the value is a valid date-time format
|
|
@@ -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
|
|
@@ -484,6 +491,9 @@ export class RequestType extends ReqResType {
|
|
|
484
491
|
*/
|
|
485
492
|
private setObject(keys: Array<string | number>, values: {[key: string]: any}) {
|
|
486
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
|
+
}
|
|
487
497
|
|
|
488
498
|
for (const key of Object.keys(property.properties)) {
|
|
489
499
|
|
|
@@ -784,15 +794,16 @@ export class RequestType extends ReqResType {
|
|
|
784
794
|
*/
|
|
785
795
|
private makeSwaggerProperyFromObject(keys: Array<string | number>, tabCount: number): string {
|
|
786
796
|
|
|
787
|
-
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
|
+
}
|
|
788
801
|
|
|
802
|
+
const space = ' '.repeat(tabCount);
|
|
789
803
|
let ymlString = `${space}properties:\n`;
|
|
804
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
805
|
+
const property = objectProperty.properties[key];
|
|
790
806
|
|
|
791
|
-
const properties = this.getProperty(keys).properties;
|
|
792
|
-
for (const key of Object.keys(properties)) {
|
|
793
|
-
const property = properties[key];
|
|
794
|
-
|
|
795
|
-
|
|
796
807
|
ymlString += `${space} ${key}:\n`;
|
|
797
808
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
798
809
|
const descJoin = `\n${space} `;
|
|
@@ -801,7 +812,7 @@ export class RequestType extends ReqResType {
|
|
|
801
812
|
ymlString += `${descJoin}enum list`;
|
|
802
813
|
ymlString += `${Object.entries(property.enums).map(([key, value]) => `${descJoin}- ${key}: ${value}`)}\n`;
|
|
803
814
|
} else if ((property.description ?? '') !== '') {
|
|
804
|
-
ymlString += `${space} description: |${descJoin}${property.description.replaceAll('\n', descJoin)}\n`;
|
|
815
|
+
ymlString += `${space} description: |${descJoin}${(property.description ?? "").replaceAll('\n', descJoin)}\n`;
|
|
805
816
|
}
|
|
806
817
|
|
|
807
818
|
if (property.type === 'enum' || property.type === 'enum?') {
|
|
@@ -840,19 +851,22 @@ export class RequestType extends ReqResType {
|
|
|
840
851
|
*/
|
|
841
852
|
private makeSwaggerPropertyFromArray(keys: Array<string | number>, tabCount: number): string {
|
|
842
853
|
|
|
843
|
-
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
|
+
}
|
|
844
858
|
|
|
845
859
|
const space = ' '.repeat(tabCount);
|
|
846
860
|
|
|
847
861
|
let ymlString = `${space}items:\n`;
|
|
848
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
849
|
-
if ((
|
|
862
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
863
|
+
if ((arrayProperty.properties.description ?? '') !== '') {
|
|
850
864
|
const descJoin = `\n${space} `;
|
|
851
|
-
ymlString += `${space} description: |${descJoin}${
|
|
865
|
+
ymlString += `${space} description: |${descJoin}${(arrayProperty.properties.description ?? '').replaceAll('\n', descJoin)}\n`;
|
|
852
866
|
}
|
|
853
867
|
|
|
854
868
|
|
|
855
|
-
switch (
|
|
869
|
+
switch (arrayProperty.properties.type) {
|
|
856
870
|
case 'object':
|
|
857
871
|
case 'object?':
|
|
858
872
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
|
@@ -60,30 +60,38 @@ 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
|
-
resData[key] =
|
|
86
|
-
|
|
68
|
+
console.log(objectProperty);
|
|
69
|
+
for (const keys of Object.keys(objectProperty.properties)) {
|
|
70
|
+
for (const key of Object.keys(objectProperty)) {
|
|
71
|
+
console.log(key);
|
|
72
|
+
if (key in data === false || data[key] === undefined) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const property = objectProperty.properties[key];
|
|
77
|
+
if (data[key] === null || (property.type.replace("?", "") !== "string" && data[key] === "")) {
|
|
78
|
+
resData[key] = property.type.endsWith('?') ? null : undefined;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
switch (property.type) {
|
|
83
|
+
case 'object':
|
|
84
|
+
case 'object?':
|
|
85
|
+
resData[key] = this.getObject([...keys, key]);
|
|
86
|
+
break;
|
|
87
|
+
case 'array':
|
|
88
|
+
case 'array?':
|
|
89
|
+
resData[key] = this.getArray([...keys, key]);
|
|
90
|
+
break;
|
|
91
|
+
default:
|
|
92
|
+
resData[key] = this.getValue([...keys, key]);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
|
|
@@ -103,13 +111,19 @@ export class ResponseType extends ReqResType {
|
|
|
103
111
|
return undefined;
|
|
104
112
|
}
|
|
105
113
|
|
|
106
|
-
const
|
|
114
|
+
const arrayProperty = this.getProperty(keys);
|
|
115
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
116
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
107
119
|
let resData: Array<any> = [];
|
|
108
120
|
for (let i = 0;i < data.length; i++) {
|
|
109
|
-
switch (properties.type) {
|
|
121
|
+
switch (arrayProperty.properties.type) {
|
|
110
122
|
case 'object':
|
|
111
123
|
case 'object?':
|
|
112
|
-
|
|
124
|
+
const value = this.getObject([...keys, i])
|
|
125
|
+
console.log(value)
|
|
126
|
+
resData.push(value);
|
|
113
127
|
break;
|
|
114
128
|
case 'array':
|
|
115
129
|
case 'array?':
|
|
@@ -344,12 +358,15 @@ export class ResponseType extends ReqResType {
|
|
|
344
358
|
*/
|
|
345
359
|
private makeSwaggerProperyFromObject(keys: Array<string | number>, tabCount: number): string {
|
|
346
360
|
|
|
361
|
+
const objectProperty = this.getProperty(keys);
|
|
362
|
+
if (objectProperty.type !== 'object' && objectProperty.type !== 'object?') {
|
|
363
|
+
throw new Error(`getObjectメソッドでObject型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
364
|
+
}
|
|
365
|
+
|
|
347
366
|
const space = ' '.repeat(tabCount);
|
|
348
367
|
let ymlString = `${space}properties:\n`;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
for (const key of Object.keys(properties)) {
|
|
352
|
-
const property = properties[key];
|
|
368
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
369
|
+
const property = objectProperty.properties[key];
|
|
353
370
|
|
|
354
371
|
ymlString += `${space} ${key}:\n`;
|
|
355
372
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
@@ -384,16 +401,19 @@ export class ResponseType extends ReqResType {
|
|
|
384
401
|
*/
|
|
385
402
|
private makeSwaggerPropertyFromArray(keys: Array<string | number>, tabCount: number): string {
|
|
386
403
|
|
|
387
|
-
const
|
|
388
|
-
|
|
404
|
+
const arrayProperty = this.getProperty(keys);
|
|
405
|
+
if (arrayProperty.type !== 'array' && arrayProperty.type !== 'array?') {
|
|
406
|
+
throw new Error(`getArrayメソッドでArray型以外が入力された場合はエラー\n keys: ${keys.join(',')}`);
|
|
407
|
+
}
|
|
389
408
|
|
|
409
|
+
const space = ' '.repeat(tabCount);
|
|
390
410
|
let ymlString = `${space}items:\n`;
|
|
391
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
392
|
-
if (
|
|
411
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
412
|
+
if (arrayProperty.properties.description !== undefined) {
|
|
393
413
|
const joinSpace = `\n${space} `;
|
|
394
|
-
ymlString += `${space} description: |${joinSpace}${
|
|
414
|
+
ymlString += `${space} description: |${joinSpace}${arrayProperty.properties.description.replaceAll("\n", joinSpace)}\n`;
|
|
395
415
|
}
|
|
396
|
-
switch (
|
|
416
|
+
switch (arrayProperty.properties.type) {
|
|
397
417
|
case 'object':
|
|
398
418
|
case 'object?':
|
|
399
419
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|