pg-mvc-service 2.0.111 → 2.0.113
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/Service.js +8 -0
- package/dist/documents/Swagger.js +2 -1
- package/dist/reqestResponse/RequestType.js +76 -35
- package/dist/reqestResponse/ResponseType.js +7 -16
- package/package.json +1 -1
- package/src/Service.ts +13 -0
- package/src/documents/Swagger.ts +2 -1
- package/src/reqestResponse/RequestType.ts +78 -39
- package/src/reqestResponse/ResponseType.ts +9 -23
package/dist/Service.js
CHANGED
|
@@ -34,6 +34,13 @@ class Service {
|
|
|
34
34
|
get Response() { return this.response; }
|
|
35
35
|
; // swaggerで必要なので、ここだけ宣言
|
|
36
36
|
get Tags() { return this.tags; }
|
|
37
|
+
get ErrorList() {
|
|
38
|
+
return [...this.errorList, {
|
|
39
|
+
status: 500,
|
|
40
|
+
code: '',
|
|
41
|
+
description: 'サーバー内部エラー(予期せぬエラー)'
|
|
42
|
+
}];
|
|
43
|
+
}
|
|
37
44
|
constructor(request, response) {
|
|
38
45
|
this.method = 'GET';
|
|
39
46
|
this.endpoint = '';
|
|
@@ -44,6 +51,7 @@ class Service {
|
|
|
44
51
|
this.response = new ResponseType_1.ResponseType();
|
|
45
52
|
this.isTest = process.env.NODE_ENV === 'test';
|
|
46
53
|
this.tags = [];
|
|
54
|
+
this.errorList = [];
|
|
47
55
|
this.dbUser = process.env.DB_USER;
|
|
48
56
|
this.dbHost = process.env.DB_HOST;
|
|
49
57
|
this.dbName = process.env.DB_DATABASE;
|
|
@@ -59,7 +59,8 @@ const createSwagger = (services, name, url, params = []) => {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
yml += service.Request.createSwagger(service.Method);
|
|
62
|
-
|
|
62
|
+
const errorList = [...service.ErrorList, ...service.Request.getInputErrorList(service.Method, service.ApiCode)];
|
|
63
|
+
yml += service.Response.createSwagger(errorList);
|
|
63
64
|
endpontSwaggerYml[service.Endpoint][service.Method] = yml;
|
|
64
65
|
}
|
|
65
66
|
let swaggerInfo = `openapi: 3.0.0
|
|
@@ -239,8 +239,7 @@ class RequestType extends ReqResType_1.default {
|
|
|
239
239
|
this.data = request.body;
|
|
240
240
|
}
|
|
241
241
|
if (this.data === undefined) {
|
|
242
|
-
|
|
243
|
-
throw new Error(`リクエストBodyがundefinedです。`);
|
|
242
|
+
this.data = {};
|
|
244
243
|
}
|
|
245
244
|
for (const key of Object.keys(this.properties)) {
|
|
246
245
|
// NULLチェック
|
|
@@ -1013,44 +1012,86 @@ class RequestType extends ReqResType_1.default {
|
|
|
1013
1012
|
}
|
|
1014
1013
|
return ymlString;
|
|
1015
1014
|
}
|
|
1016
|
-
|
|
1015
|
+
getInputErrorList(method, code) {
|
|
1017
1016
|
const errorList = [];
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1017
|
+
for (const [key, property] of Object.entries(this.properties)) {
|
|
1018
|
+
if (property.type.endsWith('?') === false) {
|
|
1019
|
+
const errorCode = property.type === 'array' && ['GET', 'DELETE'].includes(method) ? 'REQUIRE_00' : 'REQUIRE_01';
|
|
1020
|
+
errorList.push({
|
|
1021
|
+
status: 400,
|
|
1022
|
+
code: code + '-' + errorCode,
|
|
1023
|
+
description: this.throwInputError(errorCode, [key], "")
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
switch (property.type) {
|
|
1027
|
+
case 'object':
|
|
1028
|
+
case 'object?':
|
|
1024
1029
|
errorList.push({
|
|
1025
1030
|
status: 400,
|
|
1026
|
-
code: code + '',
|
|
1027
|
-
description:
|
|
1031
|
+
code: code + '-OBJECT_01',
|
|
1032
|
+
description: this.throwInputError('OBJECT_01', [key], "")
|
|
1028
1033
|
});
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1034
|
+
break;
|
|
1035
|
+
case 'array':
|
|
1036
|
+
case 'array?':
|
|
1037
|
+
errorList.push({
|
|
1038
|
+
status: 400,
|
|
1039
|
+
code: code + '-ARRAY_01',
|
|
1040
|
+
description: this.throwInputError('ARRAY_01', [key], "")
|
|
1041
|
+
});
|
|
1042
|
+
break;
|
|
1043
|
+
case 'map':
|
|
1044
|
+
case 'map?':
|
|
1045
|
+
switch (property.mapType) {
|
|
1046
|
+
case 'number':
|
|
1047
|
+
errorList.push({
|
|
1048
|
+
status: 400,
|
|
1049
|
+
code: code + '-MAP_01',
|
|
1050
|
+
description: this.throwInputError('MAP_01', [key], "")
|
|
1051
|
+
});
|
|
1052
|
+
break;
|
|
1053
|
+
case 'string':
|
|
1054
|
+
errorList.push({
|
|
1055
|
+
status: 400,
|
|
1056
|
+
code: code + '-MAP_02',
|
|
1057
|
+
description: this.throwInputError('MAP_02', [key], "")
|
|
1058
|
+
});
|
|
1059
|
+
break;
|
|
1060
|
+
case 'bool':
|
|
1061
|
+
errorList.push({
|
|
1062
|
+
status: 400,
|
|
1063
|
+
code: code + '-MAP_03',
|
|
1064
|
+
description: this.throwInputError('MAP_03', [key], "")
|
|
1065
|
+
});
|
|
1066
|
+
errorList.push({
|
|
1067
|
+
status: 400,
|
|
1068
|
+
code: code + '-MAP_04',
|
|
1069
|
+
description: this.throwInputError('MAP_04', [key], "")
|
|
1070
|
+
});
|
|
1071
|
+
errorList.push({
|
|
1072
|
+
status: 400,
|
|
1073
|
+
code: code + '-MAP_05',
|
|
1074
|
+
description: this.throwInputError('MAP_05', [key], "")
|
|
1075
|
+
});
|
|
1076
|
+
break;
|
|
1077
|
+
}
|
|
1078
|
+
break;
|
|
1079
|
+
case 'enum':
|
|
1080
|
+
case 'enum?':
|
|
1081
|
+
break;
|
|
1082
|
+
default:
|
|
1083
|
+
break;
|
|
1053
1084
|
}
|
|
1085
|
+
// this.changeBody([key], mapData);
|
|
1086
|
+
// break;
|
|
1087
|
+
// case 'enum':
|
|
1088
|
+
// case 'enum?':
|
|
1089
|
+
// this.setEnum([key], value);
|
|
1090
|
+
// break;
|
|
1091
|
+
// default:
|
|
1092
|
+
// this.convertInput([key], value);
|
|
1093
|
+
// break;
|
|
1094
|
+
// }
|
|
1054
1095
|
}
|
|
1055
1096
|
return errorList;
|
|
1056
1097
|
}
|
|
@@ -10,7 +10,6 @@ const ReqResType_1 = __importDefault(require("./ReqResType"));
|
|
|
10
10
|
class ResponseType extends ReqResType_1.default {
|
|
11
11
|
constructor() {
|
|
12
12
|
super(...arguments);
|
|
13
|
-
this.errorList = [];
|
|
14
13
|
/**
|
|
15
14
|
* Property to store response data
|
|
16
15
|
* レスポンスデータを格納するためのプロパティ
|
|
@@ -338,7 +337,7 @@ class ResponseType extends ReqResType_1.default {
|
|
|
338
337
|
* @returns {string} Swagger format response definition
|
|
339
338
|
* Swagger形式のレスポンス定義
|
|
340
339
|
*/
|
|
341
|
-
createSwagger(
|
|
340
|
+
createSwagger(errorList) {
|
|
342
341
|
let ymlString = ` responses:
|
|
343
342
|
'200':
|
|
344
343
|
description: 成功事レスポンス
|
|
@@ -376,19 +375,13 @@ class ResponseType extends ReqResType_1.default {
|
|
|
376
375
|
break;
|
|
377
376
|
}
|
|
378
377
|
}
|
|
379
|
-
const errorList = [...this.errorList, ...requestErrorList];
|
|
380
|
-
errorList.push({
|
|
381
|
-
status: 500,
|
|
382
|
-
code: '',
|
|
383
|
-
description: 'サーバー内部エラー(予期せぬエラー)'
|
|
384
|
-
});
|
|
385
378
|
// statusごとにグルーピング
|
|
386
379
|
const grouped = {};
|
|
387
|
-
for (const
|
|
388
|
-
if (grouped[
|
|
389
|
-
grouped[
|
|
380
|
+
for (const error of errorList) {
|
|
381
|
+
if (grouped[error.status] === undefined) {
|
|
382
|
+
grouped[error.status] = [];
|
|
390
383
|
}
|
|
391
|
-
grouped[
|
|
384
|
+
grouped[error.status].push(error);
|
|
392
385
|
}
|
|
393
386
|
// 出力順(存在するものだけ出す)
|
|
394
387
|
const statusOrder = [400, 401, 404, 409, 422, 500];
|
|
@@ -400,16 +393,14 @@ class ResponseType extends ReqResType_1.default {
|
|
|
400
393
|
const descIndentJoin = '\n ';
|
|
401
394
|
if (list.length === 1) {
|
|
402
395
|
// 単一エラーは1行説明
|
|
403
|
-
ymlString += `
|
|
404
|
-
'${status}':
|
|
396
|
+
ymlString += ` '${status}':
|
|
405
397
|
description: ${list[0].code}: ${list[0].description}
|
|
406
398
|
`;
|
|
407
399
|
}
|
|
408
400
|
else {
|
|
409
401
|
// 複数エラーは箇条書き
|
|
410
402
|
const bullets = list.map(e => `- ${e.code !== '' ? `${e.code}: ` : ''}${e.description}`).join(descIndentJoin);
|
|
411
|
-
ymlString += `
|
|
412
|
-
'${status}':
|
|
403
|
+
ymlString += ` '${status}':
|
|
413
404
|
description: |${descIndentJoin}${bullets}
|
|
414
405
|
`;
|
|
415
406
|
}
|
package/package.json
CHANGED
package/src/Service.ts
CHANGED
|
@@ -11,6 +11,11 @@ import { EncryptClient } from './clients/EncryptClient';
|
|
|
11
11
|
import PoolManager from './PoolManager';
|
|
12
12
|
|
|
13
13
|
export type MethodType = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
14
|
+
export interface IError {
|
|
15
|
+
status: 400 | 401 | 404 | 409 | 422 | 500,
|
|
16
|
+
code: string;
|
|
17
|
+
description: string;
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
export class Service {
|
|
16
21
|
protected readonly method: MethodType = 'GET';
|
|
@@ -31,6 +36,14 @@ export class Service {
|
|
|
31
36
|
protected readonly isTest: boolean = process.env.NODE_ENV === 'test';
|
|
32
37
|
protected readonly tags: Array<string> = [];
|
|
33
38
|
get Tags(): Array<string> { return this.tags; }
|
|
39
|
+
protected readonly errorList: Array<IError> = [];
|
|
40
|
+
get ErrorList(): Array<IError> {
|
|
41
|
+
return [...this.errorList, {
|
|
42
|
+
status: 500,
|
|
43
|
+
code: '',
|
|
44
|
+
description: 'サーバー内部エラー(予期せぬエラー)'
|
|
45
|
+
}];
|
|
46
|
+
}
|
|
34
47
|
|
|
35
48
|
protected readonly req: Request;
|
|
36
49
|
protected readonly res: Response;
|
package/src/documents/Swagger.ts
CHANGED
|
@@ -72,7 +72,8 @@ export const createSwagger = (services: Service[], name: string, url: string, pa
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
yml += service.Request.createSwagger(service.Method);
|
|
75
|
-
|
|
75
|
+
const errorList = [...service.ErrorList, ...service.Request.getInputErrorList(service.Method, service.ApiCode)]
|
|
76
|
+
yml += service.Response.createSwagger(errorList);
|
|
76
77
|
|
|
77
78
|
endpontSwaggerYml[service.Endpoint][service.Method] = yml;
|
|
78
79
|
}
|
|
@@ -3,7 +3,7 @@ import ReqResType, { EnumType, NumberType, PrimitiveType, PropertyType, StringTy
|
|
|
3
3
|
import { InputErrorException } from '../exceptions/Exception';
|
|
4
4
|
import StringUtil from '../Utils/StringUtil';
|
|
5
5
|
import { ValidateStringUtil } from 'type-utils-n-daira';
|
|
6
|
-
import { IError } from '
|
|
6
|
+
import { IError } from '../Service';
|
|
7
7
|
|
|
8
8
|
// エラーメッセージの型定義
|
|
9
9
|
export interface ErrorMessageType {
|
|
@@ -280,8 +280,7 @@ export class RequestType extends ReqResType {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
if (this.data === undefined) {
|
|
283
|
-
|
|
284
|
-
throw new Error(`リクエストBodyがundefinedです。`);
|
|
283
|
+
this.data = {};
|
|
285
284
|
}
|
|
286
285
|
|
|
287
286
|
for (const key of Object.keys(this.properties)) {
|
|
@@ -1100,48 +1099,88 @@ export class RequestType extends ReqResType {
|
|
|
1100
1099
|
return ymlString;
|
|
1101
1100
|
}
|
|
1102
1101
|
|
|
1103
|
-
public
|
|
1102
|
+
public getInputErrorList(method: string, code: string): Array<IError> {
|
|
1104
1103
|
const errorList: Array<IError> = [];
|
|
1104
|
+
for (const [key, property] of Object.entries(this.properties)) {
|
|
1105
|
+
if (property.type.endsWith('?') === false) {
|
|
1106
|
+
const errorCode = property.type === 'array' && ['GET', 'DELETE'].includes(method) ? 'REQUIRE_00' : 'REQUIRE_01';
|
|
1107
|
+
errorList.push({
|
|
1108
|
+
status: 400,
|
|
1109
|
+
code: code + '-' + errorCode,
|
|
1110
|
+
description: this.throwInputError(errorCode, [key], "")
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1105
1113
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
const space = ' '.repeat(tabCount);
|
|
1110
|
-
|
|
1111
|
-
let ymlString = '';
|
|
1112
|
-
for (const [key, property] of Object.entries(this.properties)) {
|
|
1113
|
-
if (property.type.endsWith('?') === false) {
|
|
1114
|
+
switch (property.type) {
|
|
1115
|
+
case 'object':
|
|
1116
|
+
case 'object?':
|
|
1114
1117
|
errorList.push({
|
|
1115
1118
|
status: 400,
|
|
1116
|
-
code: code + '',
|
|
1117
|
-
description:
|
|
1119
|
+
code: code + '-OBJECT_01',
|
|
1120
|
+
description: this.throwInputError('OBJECT_01', [key], "")
|
|
1118
1121
|
});
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1122
|
+
break;
|
|
1123
|
+
case 'array':
|
|
1124
|
+
case 'array?':
|
|
1125
|
+
errorList.push({
|
|
1126
|
+
status: 400,
|
|
1127
|
+
code: code + '-ARRAY_01',
|
|
1128
|
+
description: this.throwInputError('ARRAY_01', [key], "")
|
|
1129
|
+
});
|
|
1130
|
+
break;
|
|
1131
|
+
case 'map':
|
|
1132
|
+
case 'map?':
|
|
1133
|
+
switch (property.mapType) {
|
|
1134
|
+
case 'number':
|
|
1135
|
+
errorList.push({
|
|
1136
|
+
status: 400,
|
|
1137
|
+
code: code + '-MAP_01',
|
|
1138
|
+
description: this.throwInputError('MAP_01', [key], "")
|
|
1139
|
+
});
|
|
1140
|
+
break;
|
|
1141
|
+
case 'string':
|
|
1142
|
+
errorList.push({
|
|
1143
|
+
status: 400,
|
|
1144
|
+
code: code + '-MAP_02',
|
|
1145
|
+
description: this.throwInputError('MAP_02', [key], "")
|
|
1146
|
+
});
|
|
1147
|
+
break;
|
|
1148
|
+
case 'bool':
|
|
1149
|
+
errorList.push({
|
|
1150
|
+
status: 400,
|
|
1151
|
+
code: code + '-MAP_03',
|
|
1152
|
+
description: this.throwInputError('MAP_03', [key], "")
|
|
1153
|
+
});
|
|
1154
|
+
errorList.push({
|
|
1155
|
+
status: 400,
|
|
1156
|
+
code: code + '-MAP_04',
|
|
1157
|
+
description: this.throwInputError('MAP_04', [key], "")
|
|
1158
|
+
});
|
|
1159
|
+
errorList.push({
|
|
1160
|
+
status: 400,
|
|
1161
|
+
code: code + '-MAP_05',
|
|
1162
|
+
description: this.throwInputError('MAP_05', [key], "")
|
|
1163
|
+
});
|
|
1164
|
+
break;
|
|
1165
|
+
}
|
|
1166
|
+
break;
|
|
1167
|
+
case 'enum':
|
|
1168
|
+
case 'enum?':
|
|
1169
|
+
break;
|
|
1170
|
+
default:
|
|
1171
|
+
break;
|
|
1144
1172
|
}
|
|
1173
|
+
|
|
1174
|
+
// this.changeBody([key], mapData);
|
|
1175
|
+
// break;
|
|
1176
|
+
// case 'enum':
|
|
1177
|
+
// case 'enum?':
|
|
1178
|
+
// this.setEnum([key], value);
|
|
1179
|
+
// break;
|
|
1180
|
+
// default:
|
|
1181
|
+
// this.convertInput([key], value);
|
|
1182
|
+
// break;
|
|
1183
|
+
// }
|
|
1145
1184
|
}
|
|
1146
1185
|
|
|
1147
1186
|
return errorList;
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { ValidateStringUtil } from "type-utils-n-daira";
|
|
2
2
|
import StringUtil from "../Utils/StringUtil";
|
|
3
3
|
import ReqResType, { PropertyType } from "./ReqResType";
|
|
4
|
+
import { IError } from "../Service";
|
|
4
5
|
|
|
5
|
-
export interface IError {
|
|
6
|
-
status: 400 | 401 | 404 | 409 | 422 | 500,
|
|
7
|
-
code: string;
|
|
8
|
-
description: string;
|
|
9
|
-
}
|
|
10
6
|
|
|
11
|
-
export class ResponseType extends ReqResType {
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
export class ResponseType extends ReqResType {
|
|
14
9
|
|
|
15
10
|
/**
|
|
16
11
|
* Property to store response data
|
|
@@ -375,7 +370,7 @@ export class ResponseType extends ReqResType {
|
|
|
375
370
|
* @returns {string} Swagger format response definition
|
|
376
371
|
* Swagger形式のレスポンス定義
|
|
377
372
|
*/
|
|
378
|
-
public createSwagger(
|
|
373
|
+
public createSwagger(errorList: Array<IError>): string {
|
|
379
374
|
let ymlString = ` responses:
|
|
380
375
|
'200':
|
|
381
376
|
description: 成功事レスポンス
|
|
@@ -418,20 +413,14 @@ export class ResponseType extends ReqResType {
|
|
|
418
413
|
}
|
|
419
414
|
}
|
|
420
415
|
|
|
421
|
-
const errorList: Array<IError> = [...this.errorList, ...requestErrorList];
|
|
422
|
-
errorList.push({
|
|
423
|
-
status: 500,
|
|
424
|
-
code: '',
|
|
425
|
-
description: 'サーバー内部エラー(予期せぬエラー)'
|
|
426
|
-
})
|
|
427
416
|
|
|
428
417
|
// statusごとにグルーピング
|
|
429
418
|
const grouped: { [status: number]: IError[] } = {};
|
|
430
|
-
for (const
|
|
431
|
-
if (grouped[
|
|
432
|
-
grouped[
|
|
419
|
+
for (const error of errorList) {
|
|
420
|
+
if (grouped[error.status] === undefined) {
|
|
421
|
+
grouped[error.status] = [];
|
|
433
422
|
}
|
|
434
|
-
grouped[
|
|
423
|
+
grouped[error.status].push(error);
|
|
435
424
|
}
|
|
436
425
|
|
|
437
426
|
// 出力順(存在するものだけ出す)
|
|
@@ -445,19 +434,16 @@ export class ResponseType extends ReqResType {
|
|
|
445
434
|
|
|
446
435
|
if (list.length === 1) {
|
|
447
436
|
// 単一エラーは1行説明
|
|
448
|
-
ymlString += `
|
|
449
|
-
'${status}':
|
|
437
|
+
ymlString += ` '${status}':
|
|
450
438
|
description: ${list[0].code}: ${list[0].description}
|
|
451
439
|
`;
|
|
452
440
|
} else {
|
|
453
441
|
// 複数エラーは箇条書き
|
|
454
442
|
const bullets = list.map(e => `- ${e.code !== '' ? `${e.code}: ` : ''}${e.description}`).join(descIndentJoin);
|
|
455
|
-
ymlString += `
|
|
456
|
-
'${status}':
|
|
443
|
+
ymlString += ` '${status}':
|
|
457
444
|
description: |${descIndentJoin}${bullets}
|
|
458
445
|
`;
|
|
459
446
|
}
|
|
460
|
-
|
|
461
447
|
}
|
|
462
448
|
|
|
463
449
|
return ymlString;
|