pg-mvc-service 2.0.53 → 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 +52 -52
- package/dist/reqestResponse/RequestType.js +28 -12
- package/dist/reqestResponse/ResponseType.js +46 -32
- package/package.json +1 -1
- package/src/reqestResponse/ReqResType.ts +55 -55
- package/src/reqestResponse/RequestType.ts +28 -14
- package/src/reqestResponse/ResponseType.ts +51 -35
|
@@ -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,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]));
|
|
@@ -314,11 +322,14 @@ class ResponseType extends ReqResType_1.default {
|
|
|
314
322
|
* Swagger形式のプロパティ定義
|
|
315
323
|
*/
|
|
316
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
|
+
}
|
|
317
329
|
const space = ' '.repeat(tabCount);
|
|
318
330
|
let ymlString = `${space}properties:\n`;
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
const property = properties[key];
|
|
331
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
332
|
+
const property = objectProperty.properties[key];
|
|
322
333
|
ymlString += `${space} ${key}:\n`;
|
|
323
334
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
324
335
|
if (property.description !== undefined) {
|
|
@@ -349,15 +360,18 @@ class ResponseType extends ReqResType_1.default {
|
|
|
349
360
|
* @returns {string} Swagger format property definition, Swagger形式のプロパティ定義
|
|
350
361
|
*/
|
|
351
362
|
makeSwaggerPropertyFromArray(keys, tabCount) {
|
|
352
|
-
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
|
+
}
|
|
353
367
|
const space = ' '.repeat(tabCount);
|
|
354
368
|
let ymlString = `${space}items:\n`;
|
|
355
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
356
|
-
if (
|
|
369
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
370
|
+
if (arrayProperty.properties.description !== undefined) {
|
|
357
371
|
const joinSpace = `\n${space} `;
|
|
358
|
-
ymlString += `${space} description: |${joinSpace}${
|
|
372
|
+
ymlString += `${space} description: |${joinSpace}${arrayProperty.properties.description.replaceAll("\n", joinSpace)}\n`;
|
|
359
373
|
}
|
|
360
|
-
switch (
|
|
374
|
+
switch (arrayProperty.properties.type) {
|
|
361
375
|
case 'object':
|
|
362
376
|
case 'object?':
|
|
363
377
|
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,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]));
|
|
@@ -344,12 +354,15 @@ export class ResponseType extends ReqResType {
|
|
|
344
354
|
*/
|
|
345
355
|
private makeSwaggerProperyFromObject(keys: Array<string | number>, tabCount: number): string {
|
|
346
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
|
+
|
|
347
362
|
const space = ' '.repeat(tabCount);
|
|
348
363
|
let ymlString = `${space}properties:\n`;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
for (const key of Object.keys(properties)) {
|
|
352
|
-
const property = properties[key];
|
|
364
|
+
for (const key of Object.keys(objectProperty.properties)) {
|
|
365
|
+
const property = objectProperty.properties[key];
|
|
353
366
|
|
|
354
367
|
ymlString += `${space} ${key}:\n`;
|
|
355
368
|
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
@@ -384,16 +397,19 @@ export class ResponseType extends ReqResType {
|
|
|
384
397
|
*/
|
|
385
398
|
private makeSwaggerPropertyFromArray(keys: Array<string | number>, tabCount: number): string {
|
|
386
399
|
|
|
387
|
-
const
|
|
388
|
-
|
|
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
|
+
}
|
|
389
404
|
|
|
405
|
+
const space = ' '.repeat(tabCount);
|
|
390
406
|
let ymlString = `${space}items:\n`;
|
|
391
|
-
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(
|
|
392
|
-
if (
|
|
407
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(arrayProperty.properties)}\n`;
|
|
408
|
+
if (arrayProperty.properties.description !== undefined) {
|
|
393
409
|
const joinSpace = `\n${space} `;
|
|
394
|
-
ymlString += `${space} description: |${joinSpace}${
|
|
410
|
+
ymlString += `${space} description: |${joinSpace}${arrayProperty.properties.description.replaceAll("\n", joinSpace)}\n`;
|
|
395
411
|
}
|
|
396
|
-
switch (
|
|
412
|
+
switch (arrayProperty.properties.type) {
|
|
397
413
|
case 'object':
|
|
398
414
|
case 'object?':
|
|
399
415
|
ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|