pg-mvc-service 2.0.104 → 2.0.107
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/documents/Swagger.js +1 -1
- package/dist/reqestResponse/RequestType.js +41 -21
- package/dist/reqestResponse/ResponseType.js +98 -1
- package/package.json +1 -1
- package/src/documents/Swagger.ts +1 -1
- package/src/reqestResponse/RequestType.ts +43 -22
- package/src/reqestResponse/ResponseType.ts +107 -1
|
@@ -59,7 +59,7 @@ const createSwagger = (services, name, url, params = []) => {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
yml += service.Request.createSwagger(service.Method);
|
|
62
|
-
yml += service.Response.createSwagger();
|
|
62
|
+
yml += service.Response.createSwagger(service.Request.getInputErrorLost(service.Method, service.ApiCode));
|
|
63
63
|
endpontSwaggerYml[service.Endpoint][service.Method] = yml;
|
|
64
64
|
}
|
|
65
65
|
let swaggerInfo = `openapi: 3.0.0
|
|
@@ -67,27 +67,6 @@ class RequestType extends ReqResType_1.default {
|
|
|
67
67
|
};
|
|
68
68
|
this.ERROR_MESSAGE = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
|
|
69
69
|
this.paramProperties = [];
|
|
70
|
-
// private makeSwaggerPropertyFromDictionary(keys: Array<string | number>, tabCount: number): string {
|
|
71
|
-
// const property = this.getProperty(keys).properties;
|
|
72
|
-
// const space = ' '.repeat(tabCount);
|
|
73
|
-
// let ymlString = `${space}items:\n`;
|
|
74
|
-
// ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
75
|
-
// if ((property.description ?? '') !== '') {
|
|
76
|
-
// const descJoin = `\n${space} `;
|
|
77
|
-
// ymlString += `${space} description: |${descJoin}${property.description.replaceAll('\n', descJoin)}\n`;
|
|
78
|
-
// }
|
|
79
|
-
// switch (property.type) {
|
|
80
|
-
// case 'object':
|
|
81
|
-
// case 'object?':
|
|
82
|
-
// ymlString += this.makeSwaggerProperyFromObject([...keys, 0], tabCount + 1);
|
|
83
|
-
// break;
|
|
84
|
-
// case 'array':
|
|
85
|
-
// case 'array?':
|
|
86
|
-
// ymlString += this.makeSwaggerPropertyFromArray([...keys, 0], tabCount + 1);
|
|
87
|
-
// break;
|
|
88
|
-
// }
|
|
89
|
-
// return ymlString;
|
|
90
|
-
// }
|
|
91
70
|
}
|
|
92
71
|
get paramPath() {
|
|
93
72
|
return this.paramProperties.map(property => `/{${property.key}}`).join("");
|
|
@@ -1034,5 +1013,46 @@ class RequestType extends ReqResType_1.default {
|
|
|
1034
1013
|
}
|
|
1035
1014
|
return ymlString;
|
|
1036
1015
|
}
|
|
1016
|
+
getInputErrorLost(method, code) {
|
|
1017
|
+
const errorList = [];
|
|
1018
|
+
if (method === 'GET' || method === 'DELETE') {
|
|
1019
|
+
const tabCount = 4;
|
|
1020
|
+
const space = ' '.repeat(tabCount);
|
|
1021
|
+
let ymlString = '';
|
|
1022
|
+
for (const [key, property] of Object.entries(this.properties)) {
|
|
1023
|
+
if (property.type.endsWith('?') === false) {
|
|
1024
|
+
errorList.push({
|
|
1025
|
+
status: 400,
|
|
1026
|
+
code: code + '',
|
|
1027
|
+
description: `${key}:未入力エラー(未指定、null、空文字の場合にエラー)`
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
// ymlString += `${space}- name: ${key}\n`;
|
|
1031
|
+
// ymlString += `${space} in: query\n`;
|
|
1032
|
+
// const descJoin = `\n${space} `;
|
|
1033
|
+
// if (property.type === 'enum' || property.type === 'enum?') {
|
|
1034
|
+
// ymlString += `${space} description: |${property.description === undefined ? '' : `${descJoin}${property.description.replaceAll("\n", descJoin)}`}`;
|
|
1035
|
+
// ymlString += `${descJoin}enum list`;
|
|
1036
|
+
// ymlString += `${Object.entries(property.enums).map(([key, value]) => `${descJoin}- ${key}: ${value}`)}\n`;
|
|
1037
|
+
// } else if (property.description !== undefined) {
|
|
1038
|
+
// ymlString += `${space} description: |\n${space} ${property.description.replaceAll("\n", descJoin)}\n`;
|
|
1039
|
+
// }
|
|
1040
|
+
// ymlString += `${space} required: ${property.type.endsWith('?') ? 'false' : 'true'}\n`;
|
|
1041
|
+
// ymlString += `${space} schema:\n`;
|
|
1042
|
+
// ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
1043
|
+
// if (property.type === 'enum' || property.type === 'enum?') {
|
|
1044
|
+
// ymlString += `${space} nullable: ${property.enumType.endsWith('?')}\n`;
|
|
1045
|
+
// ymlString += `${space} enum:\n`;
|
|
1046
|
+
// for (const type of Object.keys(property.enumType)) {
|
|
1047
|
+
// ymlString += `${space} - ${type}\n`;
|
|
1048
|
+
// }
|
|
1049
|
+
// if (property.enumType.endsWith('?')) {
|
|
1050
|
+
// ymlString += `${space} - null\n`;
|
|
1051
|
+
// }
|
|
1052
|
+
// }
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
return errorList;
|
|
1056
|
+
}
|
|
1037
1057
|
}
|
|
1038
1058
|
exports.RequestType = RequestType;
|
|
@@ -10,6 +10,7 @@ const ReqResType_1 = __importDefault(require("./ReqResType"));
|
|
|
10
10
|
class ResponseType extends ReqResType_1.default {
|
|
11
11
|
constructor() {
|
|
12
12
|
super(...arguments);
|
|
13
|
+
this.errorList = [];
|
|
13
14
|
/**
|
|
14
15
|
* Property to store response data
|
|
15
16
|
* レスポンスデータを格納するためのプロパティ
|
|
@@ -337,7 +338,7 @@ class ResponseType extends ReqResType_1.default {
|
|
|
337
338
|
* @returns {string} Swagger format response definition
|
|
338
339
|
* Swagger形式のレスポンス定義
|
|
339
340
|
*/
|
|
340
|
-
createSwagger() {
|
|
341
|
+
createSwagger(requestErrorList) {
|
|
341
342
|
let ymlString = ` responses:
|
|
342
343
|
'200':
|
|
343
344
|
description: 成功事レスポンス
|
|
@@ -375,6 +376,102 @@ class ResponseType extends ReqResType_1.default {
|
|
|
375
376
|
break;
|
|
376
377
|
}
|
|
377
378
|
}
|
|
379
|
+
const errorList = [...this.errorList, ...requestErrorList];
|
|
380
|
+
errorList.push({
|
|
381
|
+
status: 500,
|
|
382
|
+
code: '',
|
|
383
|
+
description: 'サーバー内部エラー(予期せぬエラー)'
|
|
384
|
+
});
|
|
385
|
+
// for (const error of errorList) {
|
|
386
|
+
// ymlString += `
|
|
387
|
+
// '${error.status}':
|
|
388
|
+
// description: 【エラー】${error.description}
|
|
389
|
+
// content:
|
|
390
|
+
// application/json:
|
|
391
|
+
// schema:
|
|
392
|
+
// type: object
|
|
393
|
+
// properties:`;
|
|
394
|
+
// if ([400, 404, 409, 422].includes(error.status)) {
|
|
395
|
+
// ymlString += `
|
|
396
|
+
// errorCode:
|
|
397
|
+
// type: string
|
|
398
|
+
// description: エラーコード
|
|
399
|
+
// errorMessage:
|
|
400
|
+
// type: string
|
|
401
|
+
// description: エラーメッセージ`;
|
|
402
|
+
// } else if (error.status === 401) {
|
|
403
|
+
// ymlString += `
|
|
404
|
+
// message:
|
|
405
|
+
// type: string
|
|
406
|
+
// description: Authentication expired. Please login again.`;
|
|
407
|
+
// } else if (error.status === 500) {
|
|
408
|
+
// ymlString += `
|
|
409
|
+
// message:
|
|
410
|
+
// type: string
|
|
411
|
+
// description: Internal Server Error`;
|
|
412
|
+
// }
|
|
413
|
+
// }
|
|
414
|
+
// statusごとにグルーピング
|
|
415
|
+
const grouped = {};
|
|
416
|
+
for (const e of errorList) {
|
|
417
|
+
if (grouped[e.status] === undefined) {
|
|
418
|
+
grouped[e.status] = [];
|
|
419
|
+
}
|
|
420
|
+
grouped[e.status].push(e);
|
|
421
|
+
}
|
|
422
|
+
// 出力順(存在するものだけ出す)
|
|
423
|
+
const statusOrder = [400, 401, 404, 409, 422, 500];
|
|
424
|
+
for (const status of statusOrder) {
|
|
425
|
+
const list = grouped[status];
|
|
426
|
+
if (!list || list.length === 0) {
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
const descIndentJoin = '\n ';
|
|
430
|
+
if (list.length === 1) {
|
|
431
|
+
// 単一エラーは1行説明
|
|
432
|
+
ymlString += `
|
|
433
|
+
'${status}':
|
|
434
|
+
description: 【エラー】${list[0].description}
|
|
435
|
+
content:
|
|
436
|
+
application/json:
|
|
437
|
+
schema:
|
|
438
|
+
type: object
|
|
439
|
+
properties:`;
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
// 複数エラーは箇条書き
|
|
443
|
+
const bullets = list.map(e => `- ${e.code !== '' ? `${e.code}: ` : ''}${e.description}`).join(descIndentJoin);
|
|
444
|
+
ymlString += `
|
|
445
|
+
'${status}':
|
|
446
|
+
description: |${descIndentJoin}【エラー】${descIndentJoin}${bullets}
|
|
447
|
+
content:
|
|
448
|
+
application/json:
|
|
449
|
+
schema:
|
|
450
|
+
type: object
|
|
451
|
+
properties:`;
|
|
452
|
+
}
|
|
453
|
+
if ([400, 404, 409, 422].includes(status)) {
|
|
454
|
+
ymlString += `
|
|
455
|
+
errorCode:
|
|
456
|
+
type: string
|
|
457
|
+
description: エラーコード
|
|
458
|
+
errorMessage:
|
|
459
|
+
type: string
|
|
460
|
+
description: エラーメッセージ`;
|
|
461
|
+
}
|
|
462
|
+
else if (status === 401) {
|
|
463
|
+
ymlString += `
|
|
464
|
+
message:
|
|
465
|
+
type: string
|
|
466
|
+
description: Authentication expired. Please login again.`;
|
|
467
|
+
}
|
|
468
|
+
else if (status === 500) {
|
|
469
|
+
ymlString += `
|
|
470
|
+
message:
|
|
471
|
+
type: string
|
|
472
|
+
description: Internal Server Error`;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
378
475
|
return ymlString;
|
|
379
476
|
}
|
|
380
477
|
/**
|
package/package.json
CHANGED
package/src/documents/Swagger.ts
CHANGED
|
@@ -72,7 +72,7 @@ export const createSwagger = (services: Service[], name: string, url: string, pa
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
yml += service.Request.createSwagger(service.Method);
|
|
75
|
-
yml += service.Response.createSwagger();
|
|
75
|
+
yml += service.Response.createSwagger(service.Request.getInputErrorLost(service.Method, service.ApiCode));
|
|
76
76
|
|
|
77
77
|
endpontSwaggerYml[service.Endpoint][service.Method] = yml;
|
|
78
78
|
}
|
|
@@ -3,6 +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 './ResponseType';
|
|
6
7
|
|
|
7
8
|
// エラーメッセージの型定義
|
|
8
9
|
export interface ErrorMessageType {
|
|
@@ -1099,32 +1100,52 @@ export class RequestType extends ReqResType {
|
|
|
1099
1100
|
return ymlString;
|
|
1100
1101
|
}
|
|
1101
1102
|
|
|
1102
|
-
|
|
1103
|
+
public getInputErrorLost(method: string, code: string): Array<IError> {
|
|
1104
|
+
const errorList: Array<IError> = [];
|
|
1103
1105
|
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
// const space = ' '.repeat(tabCount);
|
|
1106
|
+
if (method === 'GET' || method === 'DELETE') {
|
|
1107
1107
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
// if ((property.description ?? '') !== '') {
|
|
1111
|
-
// const descJoin = `\n${space} `;
|
|
1112
|
-
// ymlString += `${space} description: |${descJoin}${property.description.replaceAll('\n', descJoin)}\n`;
|
|
1113
|
-
// }
|
|
1108
|
+
const tabCount = 4;
|
|
1109
|
+
const space = ' '.repeat(tabCount);
|
|
1114
1110
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1111
|
+
let ymlString = '';
|
|
1112
|
+
for (const [key, property] of Object.entries(this.properties)) {
|
|
1113
|
+
if (property.type.endsWith('?') === false) {
|
|
1114
|
+
errorList.push({
|
|
1115
|
+
status: 400,
|
|
1116
|
+
code: code + '',
|
|
1117
|
+
description: `${key}:未入力エラー(未指定、null、空文字の場合にエラー)`
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
// ymlString += `${space}- name: ${key}\n`;
|
|
1121
|
+
// ymlString += `${space} in: query\n`;
|
|
1122
|
+
|
|
1123
|
+
// const descJoin = `\n${space} `;
|
|
1124
|
+
// if (property.type === 'enum' || property.type === 'enum?') {
|
|
1125
|
+
// ymlString += `${space} description: |${property.description === undefined ? '' : `${descJoin}${property.description.replaceAll("\n", descJoin)}`}`;
|
|
1126
|
+
// ymlString += `${descJoin}enum list`;
|
|
1127
|
+
// ymlString += `${Object.entries(property.enums).map(([key, value]) => `${descJoin}- ${key}: ${value}`)}\n`;
|
|
1128
|
+
// } else if (property.description !== undefined) {
|
|
1129
|
+
// ymlString += `${space} description: |\n${space} ${property.description.replaceAll("\n", descJoin)}\n`;
|
|
1130
|
+
// }
|
|
1131
|
+
// ymlString += `${space} required: ${property.type.endsWith('?') ? 'false' : 'true'}\n`;
|
|
1132
|
+
// ymlString += `${space} schema:\n`;
|
|
1133
|
+
// ymlString += `${space} type: ${this.replaceFromPropertyTypeToSwagger(property)}\n`;
|
|
1134
|
+
// if (property.type === 'enum' || property.type === 'enum?') {
|
|
1135
|
+
// ymlString += `${space} nullable: ${property.enumType.endsWith('?')}\n`;
|
|
1136
|
+
// ymlString += `${space} enum:\n`;
|
|
1137
|
+
// for (const type of Object.keys(property.enumType)) {
|
|
1138
|
+
// ymlString += `${space} - ${type}\n`;
|
|
1139
|
+
// }
|
|
1140
|
+
// if (property.enumType.endsWith('?')) {
|
|
1141
|
+
// ymlString += `${space} - null\n`;
|
|
1142
|
+
// }
|
|
1143
|
+
// }
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1125
1146
|
|
|
1126
|
-
|
|
1127
|
-
|
|
1147
|
+
return errorList;
|
|
1148
|
+
}
|
|
1128
1149
|
}
|
|
1129
1150
|
|
|
1130
1151
|
// Requestのheaderで定義されているIFをそのまま拝借
|
|
@@ -2,8 +2,16 @@ import { ValidateStringUtil } from "type-utils-n-daira";
|
|
|
2
2
|
import StringUtil from "../Utils/StringUtil";
|
|
3
3
|
import ReqResType, { PropertyType } from "./ReqResType";
|
|
4
4
|
|
|
5
|
+
export interface IError {
|
|
6
|
+
status: 400 | 401 | 404 | 409 | 422 | 500,
|
|
7
|
+
code: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
export class ResponseType extends ReqResType {
|
|
6
12
|
|
|
13
|
+
protected readonly errorList: Array<IError> = [];
|
|
14
|
+
|
|
7
15
|
/**
|
|
8
16
|
* Property to store response data
|
|
9
17
|
* レスポンスデータを格納するためのプロパティ
|
|
@@ -367,7 +375,7 @@ export class ResponseType extends ReqResType {
|
|
|
367
375
|
* @returns {string} Swagger format response definition
|
|
368
376
|
* Swagger形式のレスポンス定義
|
|
369
377
|
*/
|
|
370
|
-
public createSwagger(): string {
|
|
378
|
+
public createSwagger(requestErrorList: Array<IError>): string {
|
|
371
379
|
let ymlString = ` responses:
|
|
372
380
|
'200':
|
|
373
381
|
description: 成功事レスポンス
|
|
@@ -410,6 +418,104 @@ export class ResponseType extends ReqResType {
|
|
|
410
418
|
}
|
|
411
419
|
}
|
|
412
420
|
|
|
421
|
+
const errorList: Array<IError> = [...this.errorList, ...requestErrorList];
|
|
422
|
+
errorList.push({
|
|
423
|
+
status: 500,
|
|
424
|
+
code: '',
|
|
425
|
+
description: 'サーバー内部エラー(予期せぬエラー)'
|
|
426
|
+
})
|
|
427
|
+
// for (const error of errorList) {
|
|
428
|
+
// ymlString += `
|
|
429
|
+
// '${error.status}':
|
|
430
|
+
// description: 【エラー】${error.description}
|
|
431
|
+
// content:
|
|
432
|
+
// application/json:
|
|
433
|
+
// schema:
|
|
434
|
+
// type: object
|
|
435
|
+
// properties:`;
|
|
436
|
+
// if ([400, 404, 409, 422].includes(error.status)) {
|
|
437
|
+
// ymlString += `
|
|
438
|
+
// errorCode:
|
|
439
|
+
// type: string
|
|
440
|
+
// description: エラーコード
|
|
441
|
+
// errorMessage:
|
|
442
|
+
// type: string
|
|
443
|
+
// description: エラーメッセージ`;
|
|
444
|
+
// } else if (error.status === 401) {
|
|
445
|
+
// ymlString += `
|
|
446
|
+
// message:
|
|
447
|
+
// type: string
|
|
448
|
+
// description: Authentication expired. Please login again.`;
|
|
449
|
+
// } else if (error.status === 500) {
|
|
450
|
+
// ymlString += `
|
|
451
|
+
// message:
|
|
452
|
+
// type: string
|
|
453
|
+
// description: Internal Server Error`;
|
|
454
|
+
// }
|
|
455
|
+
// }
|
|
456
|
+
|
|
457
|
+
// statusごとにグルーピング
|
|
458
|
+
const grouped: { [status: number]: IError[] } = {};
|
|
459
|
+
for (const e of errorList) {
|
|
460
|
+
if (grouped[e.status] === undefined) {
|
|
461
|
+
grouped[e.status] = [];
|
|
462
|
+
}
|
|
463
|
+
grouped[e.status].push(e);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// 出力順(存在するものだけ出す)
|
|
467
|
+
const statusOrder: Array<IError['status']> = [400, 401, 404, 409, 422, 500];
|
|
468
|
+
|
|
469
|
+
for (const status of statusOrder) {
|
|
470
|
+
const list = grouped[status];
|
|
471
|
+
if (!list || list.length === 0) { continue; }
|
|
472
|
+
|
|
473
|
+
const descIndentJoin = '\n ';
|
|
474
|
+
|
|
475
|
+
if (list.length === 1) {
|
|
476
|
+
// 単一エラーは1行説明
|
|
477
|
+
ymlString += `
|
|
478
|
+
'${status}':
|
|
479
|
+
description: 【エラー】${list[0].description}
|
|
480
|
+
content:
|
|
481
|
+
application/json:
|
|
482
|
+
schema:
|
|
483
|
+
type: object
|
|
484
|
+
properties:`;
|
|
485
|
+
} else {
|
|
486
|
+
// 複数エラーは箇条書き
|
|
487
|
+
const bullets = list.map(e => `- ${e.code !== '' ? `${e.code}: ` : ''}${e.description}`).join(descIndentJoin);
|
|
488
|
+
ymlString += `
|
|
489
|
+
'${status}':
|
|
490
|
+
description: |${descIndentJoin}【エラー】${descIndentJoin}${bullets}
|
|
491
|
+
content:
|
|
492
|
+
application/json:
|
|
493
|
+
schema:
|
|
494
|
+
type: object
|
|
495
|
+
properties:`;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if ([400, 404, 409, 422].includes(status)) {
|
|
499
|
+
ymlString += `
|
|
500
|
+
errorCode:
|
|
501
|
+
type: string
|
|
502
|
+
description: エラーコード
|
|
503
|
+
errorMessage:
|
|
504
|
+
type: string
|
|
505
|
+
description: エラーメッセージ`;
|
|
506
|
+
} else if (status === 401) {
|
|
507
|
+
ymlString += `
|
|
508
|
+
message:
|
|
509
|
+
type: string
|
|
510
|
+
description: Authentication expired. Please login again.`;
|
|
511
|
+
} else if (status === 500) {
|
|
512
|
+
ymlString += `
|
|
513
|
+
message:
|
|
514
|
+
type: string
|
|
515
|
+
description: Internal Server Error`;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
413
519
|
return ymlString;
|
|
414
520
|
}
|
|
415
521
|
|