pg-mvc-service 2.0.51 → 2.0.53
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 +71 -0
- package/dist/reqestResponse/RequestType.js +61 -26
- package/dist/reqestResponse/ResponseType.js +32 -23
- package/package.json +1 -1
- package/src/reqestResponse/ReqResType.ts +88 -4
- package/src/reqestResponse/RequestType.ts +72 -28
- package/src/reqestResponse/ResponseType.ts +36 -26
|
@@ -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
|
+
getProperty(keys) {
|
|
16
|
+
let property = 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
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
property = property.properties[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return property;
|
|
31
|
+
}
|
|
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
|
+
// }
|
|
7
75
|
/**
|
|
8
76
|
* Checks if the value is a valid date-time format
|
|
9
77
|
* 値が有効な日付時間形式かどうかを確認します
|
|
@@ -125,6 +193,9 @@ class ReqResType {
|
|
|
125
193
|
if (property.type === 'enum' || property.type === 'enum?') {
|
|
126
194
|
propertyType = property.enumType;
|
|
127
195
|
}
|
|
196
|
+
else if (property.type === 'dictionary' || property.type === 'dictionary?') {
|
|
197
|
+
propertyType = property.dictionaryType;
|
|
198
|
+
}
|
|
128
199
|
propertyType = propertyType.replace('?', '');
|
|
129
200
|
propertyType = propertyType.replace('number', 'integer');
|
|
130
201
|
propertyType = propertyType.replace(/datetime|date|time|uuid|mail|https|base64/g, 'string');
|
|
@@ -32,7 +32,8 @@ class RequestType extends ReqResType_1.default {
|
|
|
32
32
|
INVALID_TIME: '{property} must be a string in "hh:mi" format and a valid time. ({value})',
|
|
33
33
|
INVALID_DATETIME: '{property} must be a string in "YYYY-MM-DD hh:mi:ss" or "YYYY-MM-DDThh:mi:ss" format and a valid date and time. ({value})',
|
|
34
34
|
INVALID_BASE64: '{property} must be in Base64 format. ({value})',
|
|
35
|
-
INVALID_ENUM: '{property} must be in {enums}. ({value})'
|
|
35
|
+
INVALID_ENUM: '{property} must be in {enums}. ({value})',
|
|
36
|
+
INVALID_DICTIONAY: '{property} must be a valid dictionary key. ({value})',
|
|
36
37
|
};
|
|
37
38
|
this.ERROR_MESSAGE_JAPAN = {
|
|
38
39
|
REQUIRED: '{property}は必須項目です。',
|
|
@@ -49,10 +50,32 @@ class RequestType extends ReqResType_1.default {
|
|
|
49
50
|
INVALID_TIME: '{property}は"hh:mi"形式のstring型で入力してください。({value})',
|
|
50
51
|
INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式のstring型で入力してください。({value})',
|
|
51
52
|
INVALID_BASE64: '{property}はBase64形式のstring型で入力してください。({value})',
|
|
52
|
-
INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})'
|
|
53
|
+
INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})',
|
|
54
|
+
INVALID_DICTIONAY: '{property}は有効なKey-Value形式で入力してください。({value})'
|
|
53
55
|
};
|
|
54
56
|
this.ERROR_MESSAGE = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
|
|
55
57
|
this.paramProperties = [];
|
|
58
|
+
// private makeSwaggerPropertyFromDictionary(keys: Array<string | number>, tabCount: number): string {
|
|
59
|
+
// const property = this.getProperty(keys).properties;
|
|
60
|
+
// const space = ' '.repeat(tabCount);
|
|
61
|
+
// let ymlString = `${space}items:\n`;
|
|
62
|
+
// ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
63
|
+
// if ((property.description ?? '') !== '') {
|
|
64
|
+
// const descJoin = `\n${space} `;
|
|
65
|
+
// ymlString += `${space} description: |${descJoin}${property.description.replaceAll('\n', descJoin)}\n`;
|
|
66
|
+
// }
|
|
67
|
+
// switch (property.type) {
|
|
68
|
+
// case 'object':
|
|
69
|
+
// case 'object?':
|
|
70
|
+
// ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
|
71
|
+
// break;
|
|
72
|
+
// case 'array':
|
|
73
|
+
// case 'array?':
|
|
74
|
+
// ymlString += this.makeSwaggerPropertyFromArray([...keys, 0], tabCount + 1);
|
|
75
|
+
// break;
|
|
76
|
+
// }
|
|
77
|
+
// return ymlString;
|
|
78
|
+
// }
|
|
56
79
|
}
|
|
57
80
|
get paramPath() {
|
|
58
81
|
return this.paramProperties.map(property => `/{${property.key}}`).join("");
|
|
@@ -142,6 +165,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
142
165
|
"STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
|
|
143
166
|
"ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
|
|
144
167
|
"ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
|
|
168
|
+
"DICTIONARY_51": this.ERROR_MESSAGE.INVALID_DICTIONAY,
|
|
145
169
|
"NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
|
|
146
170
|
"BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
147
171
|
"BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
@@ -252,6 +276,9 @@ class RequestType extends ReqResType_1.default {
|
|
|
252
276
|
}
|
|
253
277
|
}
|
|
254
278
|
break;
|
|
279
|
+
case 'dictionary':
|
|
280
|
+
case 'dictionary?':
|
|
281
|
+
break;
|
|
255
282
|
case 'enum':
|
|
256
283
|
case 'enum?':
|
|
257
284
|
this.setEnum([key], value);
|
|
@@ -363,30 +390,38 @@ class RequestType extends ReqResType_1.default {
|
|
|
363
390
|
}
|
|
364
391
|
}
|
|
365
392
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
393
|
+
setDictionary(keys, values) {
|
|
394
|
+
// const property = this.getProperty(keys);
|
|
395
|
+
// for (let i = 0;i < values.length; i++) {
|
|
396
|
+
// // NULL Check
|
|
397
|
+
// if (values[i] === undefined || values[i] === null || (property.properties.type.replace("?", "") !== "string" && values[i] === "")) {
|
|
398
|
+
// if (property.properties.type.endsWith('?')) {
|
|
399
|
+
// this.changeBody([...keys, i], values[i] === undefined ? undefined : null);
|
|
400
|
+
// continue;
|
|
401
|
+
// } else {
|
|
402
|
+
// this.throwInputError("DICTIONARY_51", [...keys, i], "");
|
|
403
|
+
// }
|
|
404
|
+
// }
|
|
405
|
+
// switch (property.properties.type) {
|
|
406
|
+
// case 'object':
|
|
407
|
+
// case 'object?':
|
|
408
|
+
// this.setObject([...keys, i], values[i]);
|
|
409
|
+
// break;
|
|
410
|
+
// case 'array':
|
|
411
|
+
// case 'array?':
|
|
412
|
+
// this.setArray([...keys, i], values[i]);
|
|
413
|
+
// break;
|
|
414
|
+
// case 'enum':
|
|
415
|
+
// case 'enum?':
|
|
416
|
+
// for (const value of values) {
|
|
417
|
+
// this.setEnum([...keys, i], value);
|
|
418
|
+
// }
|
|
419
|
+
// break;
|
|
420
|
+
// default:
|
|
421
|
+
// this.convertInput([...keys, i], values[i]);
|
|
422
|
+
// break;
|
|
423
|
+
// }
|
|
424
|
+
// }
|
|
390
425
|
}
|
|
391
426
|
/**
|
|
392
427
|
* Set the value of the request body to the specified path.
|
|
@@ -115,29 +115,6 @@ class ResponseType extends ReqResType_1.default {
|
|
|
115
115
|
}
|
|
116
116
|
return resData;
|
|
117
117
|
}
|
|
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
118
|
/**
|
|
142
119
|
* Retrieve data based on the provided keys
|
|
143
120
|
* 指定されたキーに基づいてデータを取得
|
|
@@ -269,6 +246,12 @@ class ResponseType extends ReqResType_1.default {
|
|
|
269
246
|
return value;
|
|
270
247
|
}
|
|
271
248
|
return undefined;
|
|
249
|
+
case 'dictionary':
|
|
250
|
+
case 'dictionary?':
|
|
251
|
+
// if (Object.keys(property.enums).includes(value)) {
|
|
252
|
+
// return value;
|
|
253
|
+
// }
|
|
254
|
+
return undefined;
|
|
272
255
|
default:
|
|
273
256
|
return undefined;
|
|
274
257
|
}
|
|
@@ -314,6 +297,10 @@ class ResponseType extends ReqResType_1.default {
|
|
|
314
297
|
case 'array?':
|
|
315
298
|
ymlString += this.makeSwaggerPropertyFromArray([key], tabCount + 1);
|
|
316
299
|
break;
|
|
300
|
+
case 'dictionary':
|
|
301
|
+
case 'dictionary?':
|
|
302
|
+
ymlString += this.makeSwaggerPropertyFromDictionary([key], tabCount + 1);
|
|
303
|
+
break;
|
|
317
304
|
}
|
|
318
305
|
}
|
|
319
306
|
return ymlString;
|
|
@@ -347,6 +334,10 @@ class ResponseType extends ReqResType_1.default {
|
|
|
347
334
|
case 'array?':
|
|
348
335
|
ymlString += this.makeSwaggerPropertyFromArray([...keys, key], tabCount + 2);
|
|
349
336
|
break;
|
|
337
|
+
case 'dictionary':
|
|
338
|
+
case 'dictionary?':
|
|
339
|
+
ymlString += this.makeSwaggerPropertyFromDictionary([...keys, key], tabCount + 2);
|
|
340
|
+
break;
|
|
350
341
|
}
|
|
351
342
|
}
|
|
352
343
|
return ymlString;
|
|
@@ -375,8 +366,26 @@ class ResponseType extends ReqResType_1.default {
|
|
|
375
366
|
case 'array?':
|
|
376
367
|
ymlString += this.makeSwaggerPropertyFromArray([...keys, 0], tabCount + 1);
|
|
377
368
|
break;
|
|
369
|
+
case 'dictionary':
|
|
370
|
+
case 'dictionary?':
|
|
371
|
+
ymlString += this.makeSwaggerPropertyFromDictionary([...keys, 0], tabCount + 1);
|
|
372
|
+
break;
|
|
378
373
|
}
|
|
379
374
|
return ymlString;
|
|
380
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Generates Swagger properties from array type properties
|
|
378
|
+
* 配列型のプロパティからSwaggerのプロパティを生成
|
|
379
|
+
* @param {Array.<string|number>} keys - Path to the properties, プロパティへのパス
|
|
380
|
+
* @returns {string} Swagger format property definition, Swagger形式のプロパティ定義
|
|
381
|
+
*/
|
|
382
|
+
makeSwaggerPropertyFromDictionary(keys, tabCount) {
|
|
383
|
+
const property = this.getProperty(keys);
|
|
384
|
+
const space = ' '.repeat(tabCount);
|
|
385
|
+
let ymlString = `${space}properties:\n`;
|
|
386
|
+
ymlString += `${space} key:\n`;
|
|
387
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
388
|
+
return ymlString;
|
|
389
|
+
}
|
|
381
390
|
}
|
|
382
391
|
exports.ResponseType = ResponseType;
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
type PrimitiveKeyType =
|
|
2
|
+
'string' | 'number' | 'boolean' | 'date' | 'datetime' | 'time' | 'uuid' | 'mail' | 'https' | 'base64' |
|
|
3
|
+
'string?' | 'number?' | 'boolean?' | 'date?' | 'datetime?' | 'time?' | 'uuid?' | 'mail?' | 'https?' | 'base64?';
|
|
4
|
+
|
|
1
5
|
export type PrimitiveType = {
|
|
2
|
-
type:
|
|
3
|
-
'string' | 'number' | 'boolean' | 'date' | 'datetime' | 'time' | 'uuid' | 'mail' | 'https' | 'base64' |
|
|
4
|
-
'string?' | 'number?' | 'boolean?' | 'date?' | 'datetime?' | 'time?' | 'uuid?' | 'mail?' | 'https?' | 'base64?';
|
|
6
|
+
type: PrimitiveKeyType;
|
|
5
7
|
description?: string;
|
|
6
8
|
};
|
|
7
9
|
export type ObjectType = {
|
|
@@ -16,6 +18,11 @@ export type ArrayType = {
|
|
|
16
18
|
description?: string;
|
|
17
19
|
properties: PropertyType;
|
|
18
20
|
};
|
|
21
|
+
export type DictionaryType = {
|
|
22
|
+
type: 'dictionary' | 'dictionary?';
|
|
23
|
+
description?: string;
|
|
24
|
+
dictionaryType: 'string' | 'number' | 'string?' | 'number?';
|
|
25
|
+
};
|
|
19
26
|
export type EnumType = {
|
|
20
27
|
type: 'enum' | 'enum?';
|
|
21
28
|
description?: string;
|
|
@@ -23,12 +30,87 @@ export type EnumType = {
|
|
|
23
30
|
enums: {[key: string | number]: string};
|
|
24
31
|
};
|
|
25
32
|
|
|
26
|
-
export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType;
|
|
33
|
+
export type PropertyType = PrimitiveType | ObjectType | ArrayType | EnumType | DictionaryType;
|
|
27
34
|
|
|
28
35
|
export default class ReqResType {
|
|
29
36
|
|
|
30
37
|
protected properties: { [key: string]: PropertyType; } = {};
|
|
31
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
|
+
// 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
|
+
|
|
32
114
|
/**
|
|
33
115
|
* Checks if the value is a valid date-time format
|
|
34
116
|
* 値が有効な日付時間形式かどうかを確認します
|
|
@@ -161,6 +243,8 @@ export default class ReqResType {
|
|
|
161
243
|
let propertyType: string = property.type;
|
|
162
244
|
if (property.type === 'enum' || property.type === 'enum?') {
|
|
163
245
|
propertyType = property.enumType;
|
|
246
|
+
} else if (property.type === 'dictionary' || property.type === 'dictionary?') {
|
|
247
|
+
propertyType = property.dictionaryType;
|
|
164
248
|
}
|
|
165
249
|
propertyType = propertyType.replace('?', '');
|
|
166
250
|
propertyType = propertyType.replace('number', 'integer');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
-
import ReqResType, { EnumType, PrimitiveType
|
|
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';
|
|
@@ -21,6 +21,7 @@ export interface ErrorMessageType {
|
|
|
21
21
|
INVALID_DATETIME: string;
|
|
22
22
|
INVALID_BASE64: string;
|
|
23
23
|
INVALID_ENUM: string;
|
|
24
|
+
INVALID_DICTIONAY: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export class RequestType extends ReqResType {
|
|
@@ -46,7 +47,8 @@ export class RequestType extends ReqResType {
|
|
|
46
47
|
INVALID_TIME: '{property} must be a string in "hh:mi" format and a valid time. ({value})',
|
|
47
48
|
INVALID_DATETIME: '{property} must be a string in "YYYY-MM-DD hh:mi:ss" or "YYYY-MM-DDThh:mi:ss" format and a valid date and time. ({value})',
|
|
48
49
|
INVALID_BASE64: '{property} must be in Base64 format. ({value})',
|
|
49
|
-
INVALID_ENUM: '{property} must be in {enums}. ({value})'
|
|
50
|
+
INVALID_ENUM: '{property} must be in {enums}. ({value})',
|
|
51
|
+
INVALID_DICTIONAY: '{property} must be a valid dictionary key. ({value})',
|
|
50
52
|
}
|
|
51
53
|
private readonly ERROR_MESSAGE_JAPAN: ErrorMessageType = {
|
|
52
54
|
REQUIRED: '{property}は必須項目です。',
|
|
@@ -63,7 +65,8 @@ export class RequestType extends ReqResType {
|
|
|
63
65
|
INVALID_TIME: '{property}は"hh:mi"形式のstring型で入力してください。({value})',
|
|
64
66
|
INVALID_DATETIME: '{property}は"YYYY-MM-DD hh:mi:ss"または"YYYY-MM-DDThh:mi:ss"形式のstring型で入力してください。({value})',
|
|
65
67
|
INVALID_BASE64: '{property}はBase64形式のstring型で入力してください。({value})',
|
|
66
|
-
INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})'
|
|
68
|
+
INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})',
|
|
69
|
+
INVALID_DICTIONAY: '{property}は有効なKey-Value形式で入力してください。({value})'
|
|
67
70
|
}
|
|
68
71
|
protected readonly ERROR_MESSAGE: ErrorMessageType = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
|
|
69
72
|
|
|
@@ -138,6 +141,7 @@ export class RequestType extends ReqResType {
|
|
|
138
141
|
"TIME_21" | "DATETIME_21" | "DATETIME_22" | "HTTPS_21" | "BASE64_21" |
|
|
139
142
|
"REQUIRE_31" |
|
|
140
143
|
"ENUM_41" | "ENUM_42" | "NUMBER_41" | "STRING_41" |
|
|
144
|
+
"DICTIONARY_51" |
|
|
141
145
|
"NUMBER_91" | "BOOL_91" | "BOOL_92" | "BOOL_93" | "STRING_91" | "UUID_91" | "MAIL_91" | "DATE_91" | "DATE_92" |
|
|
142
146
|
"TIME_91" | "DATETIME_91" | "DATETIME_92" | "HTTPS_91" | "BASE64_91"
|
|
143
147
|
, keys: Array<string | number>, value: any): never {
|
|
@@ -170,6 +174,7 @@ export class RequestType extends ReqResType {
|
|
|
170
174
|
"STRING_41": this.ERROR_MESSAGE.INVALID_STRING,
|
|
171
175
|
"ENUM_41": this.ERROR_MESSAGE.INVALID_ENUM,
|
|
172
176
|
"ENUM_42": this.ERROR_MESSAGE.INVALID_ENUM,
|
|
177
|
+
"DICTIONARY_51": this.ERROR_MESSAGE.INVALID_DICTIONAY,
|
|
173
178
|
"NUMBER_91": this.ERROR_MESSAGE.INVALID_NUMBER,
|
|
174
179
|
"BOOL_91": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
175
180
|
"BOOL_92": this.ERROR_MESSAGE.INVALID_BOOL,
|
|
@@ -280,6 +285,9 @@ export class RequestType extends ReqResType {
|
|
|
280
285
|
}
|
|
281
286
|
}
|
|
282
287
|
break;
|
|
288
|
+
case 'dictionary':
|
|
289
|
+
case 'dictionary?':
|
|
290
|
+
break;
|
|
283
291
|
case 'enum':
|
|
284
292
|
case 'enum?':
|
|
285
293
|
this.setEnum([key], value);
|
|
@@ -399,31 +407,40 @@ export class RequestType extends ReqResType {
|
|
|
399
407
|
}
|
|
400
408
|
}
|
|
401
409
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
410
|
+
private setDictionary(keys: Array<string | number>, values: any) {
|
|
411
|
+
// const property = this.getProperty(keys);
|
|
412
|
+
// for (let i = 0;i < values.length; i++) {
|
|
413
|
+
|
|
414
|
+
// // NULL Check
|
|
415
|
+
// if (values[i] === undefined || values[i] === null || (property.properties.type.replace("?", "") !== "string" && values[i] === "")) {
|
|
416
|
+
// if (property.properties.type.endsWith('?')) {
|
|
417
|
+
// this.changeBody([...keys, i], values[i] === undefined ? undefined : null);
|
|
418
|
+
// continue;
|
|
419
|
+
// } else {
|
|
420
|
+
// this.throwInputError("DICTIONARY_51", [...keys, i], "");
|
|
421
|
+
// }
|
|
422
|
+
// }
|
|
423
|
+
|
|
424
|
+
// switch (property.properties.type) {
|
|
425
|
+
// case 'object':
|
|
426
|
+
// case 'object?':
|
|
427
|
+
// this.setObject([...keys, i], values[i]);
|
|
428
|
+
// break;
|
|
429
|
+
// case 'array':
|
|
430
|
+
// case 'array?':
|
|
431
|
+
// this.setArray([...keys, i], values[i]);
|
|
432
|
+
// break;
|
|
433
|
+
// case 'enum':
|
|
434
|
+
// case 'enum?':
|
|
435
|
+
// for (const value of values) {
|
|
436
|
+
// this.setEnum([...keys, i], value);
|
|
437
|
+
// }
|
|
438
|
+
// break;
|
|
439
|
+
// default:
|
|
440
|
+
// this.convertInput([...keys, i], values[i]);
|
|
441
|
+
// break;
|
|
442
|
+
// }
|
|
443
|
+
// }
|
|
427
444
|
}
|
|
428
445
|
|
|
429
446
|
/**
|
|
@@ -848,6 +865,33 @@ export class RequestType extends ReqResType {
|
|
|
848
865
|
|
|
849
866
|
return ymlString;
|
|
850
867
|
}
|
|
868
|
+
|
|
869
|
+
// private makeSwaggerPropertyFromDictionary(keys: Array<string | number>, tabCount: number): string {
|
|
870
|
+
|
|
871
|
+
// const property = this.getProperty(keys).properties;
|
|
872
|
+
|
|
873
|
+
// const space = ' '.repeat(tabCount);
|
|
874
|
+
|
|
875
|
+
// let ymlString = `${space}items:\n`;
|
|
876
|
+
// ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
877
|
+
// if ((property.description ?? '') !== '') {
|
|
878
|
+
// const descJoin = `\n${space} `;
|
|
879
|
+
// ymlString += `${space} description: |${descJoin}${property.description.replaceAll('\n', descJoin)}\n`;
|
|
880
|
+
// }
|
|
881
|
+
|
|
882
|
+
// switch (property.type) {
|
|
883
|
+
// case 'object':
|
|
884
|
+
// case 'object?':
|
|
885
|
+
// ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
|
886
|
+
// break;
|
|
887
|
+
// case 'array':
|
|
888
|
+
// case 'array?':
|
|
889
|
+
// ymlString += this.makeSwaggerPropertyFromArray([...keys, 0], tabCount + 1);
|
|
890
|
+
// break;
|
|
891
|
+
// }
|
|
892
|
+
|
|
893
|
+
// return ymlString;
|
|
894
|
+
// }
|
|
851
895
|
}
|
|
852
896
|
|
|
853
897
|
// Requestのheaderで定義されているIFをそのまま拝借
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValidateStringUtil } from "type-utils-n-daira";
|
|
2
2
|
import StringUtil from "../Utils/StringUtil";
|
|
3
|
-
import ReqResType from "./ReqResType";
|
|
3
|
+
import ReqResType, { PropertyType } from "./ReqResType";
|
|
4
4
|
|
|
5
5
|
export class ResponseType extends ReqResType {
|
|
6
6
|
|
|
@@ -124,31 +124,6 @@ export class ResponseType extends ReqResType {
|
|
|
124
124
|
return resData;
|
|
125
125
|
}
|
|
126
126
|
|
|
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
127
|
/**
|
|
153
128
|
* Retrieve data based on the provided keys
|
|
154
129
|
* 指定されたキーに基づいてデータを取得
|
|
@@ -291,6 +266,12 @@ export class ResponseType extends ReqResType {
|
|
|
291
266
|
return value;
|
|
292
267
|
}
|
|
293
268
|
return undefined;
|
|
269
|
+
case 'dictionary':
|
|
270
|
+
case 'dictionary?':
|
|
271
|
+
// if (Object.keys(property.enums).includes(value)) {
|
|
272
|
+
// return value;
|
|
273
|
+
// }
|
|
274
|
+
return undefined;
|
|
294
275
|
default:
|
|
295
276
|
return undefined;
|
|
296
277
|
}
|
|
@@ -343,6 +324,10 @@ export class ResponseType extends ReqResType {
|
|
|
343
324
|
case 'array?':
|
|
344
325
|
ymlString += this.makeSwaggerPropertyFromArray([key], tabCount + 1);
|
|
345
326
|
break;
|
|
327
|
+
case 'dictionary':
|
|
328
|
+
case 'dictionary?':
|
|
329
|
+
ymlString += this.makeSwaggerPropertyFromDictionary([key], tabCount + 1);
|
|
330
|
+
break;
|
|
346
331
|
}
|
|
347
332
|
}
|
|
348
333
|
|
|
@@ -381,6 +366,10 @@ export class ResponseType extends ReqResType {
|
|
|
381
366
|
case 'array?':
|
|
382
367
|
ymlString += this.makeSwaggerPropertyFromArray([...keys, key], tabCount + 2);
|
|
383
368
|
break;
|
|
369
|
+
case 'dictionary':
|
|
370
|
+
case 'dictionary?':
|
|
371
|
+
ymlString += this.makeSwaggerPropertyFromDictionary([...keys, key], tabCount + 2);
|
|
372
|
+
break;
|
|
384
373
|
}
|
|
385
374
|
}
|
|
386
375
|
|
|
@@ -413,8 +402,29 @@ export class ResponseType extends ReqResType {
|
|
|
413
402
|
case 'array?':
|
|
414
403
|
ymlString += this.makeSwaggerPropertyFromArray([...keys, 0], tabCount + 1);
|
|
415
404
|
break;
|
|
405
|
+
case 'dictionary':
|
|
406
|
+
case 'dictionary?':
|
|
407
|
+
ymlString += this.makeSwaggerPropertyFromDictionary([...keys, 0], tabCount + 1);
|
|
408
|
+
break;
|
|
416
409
|
}
|
|
417
410
|
|
|
411
|
+
return ymlString;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Generates Swagger properties from array type properties
|
|
416
|
+
* 配列型のプロパティからSwaggerのプロパティを生成
|
|
417
|
+
* @param {Array.<string|number>} keys - Path to the properties, プロパティへのパス
|
|
418
|
+
* @returns {string} Swagger format property definition, Swagger形式のプロパティ定義
|
|
419
|
+
*/
|
|
420
|
+
private makeSwaggerPropertyFromDictionary(keys: Array<string | number>, tabCount: number): string {
|
|
421
|
+
|
|
422
|
+
const property = this.getProperty(keys);
|
|
423
|
+
const space = ' '.repeat(tabCount);
|
|
424
|
+
let ymlString = `${space}properties:\n`;
|
|
425
|
+
ymlString += `${space} key:\n`;
|
|
426
|
+
ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
427
|
+
|
|
418
428
|
return ymlString;
|
|
419
429
|
}
|
|
420
430
|
}
|