pg-mvc-service 2.0.105 → 2.0.108

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.
@@ -382,16 +382,46 @@ class ResponseType extends ReqResType_1.default {
382
382
  code: '',
383
383
  description: 'サーバー内部エラー(予期せぬエラー)'
384
384
  });
385
- for (const error of errorList) {
386
- ymlString += `
387
- '${error.code}':
388
- description: 【エラー】${error.description}
385
+ // statusごとにグルーピング
386
+ const grouped = {};
387
+ for (const e of errorList) {
388
+ if (grouped[e.status] === undefined) {
389
+ grouped[e.status] = [];
390
+ }
391
+ grouped[e.status].push(e);
392
+ }
393
+ // 出力順(存在するものだけ出す)
394
+ const statusOrder = [400, 401, 404, 409, 422, 500];
395
+ for (const status of statusOrder) {
396
+ const list = grouped[status];
397
+ if (!list || list.length === 0) {
398
+ continue;
399
+ }
400
+ const descIndentJoin = '\n ';
401
+ if (list.length === 1) {
402
+ // 単一エラーは1行説明
403
+ ymlString += `
404
+ '${status}':
405
+ description: 【エラー】${list[0].description}
389
406
  content:
390
407
  application/json:
391
408
  schema:
392
409
  type: object
393
410
  properties:`;
394
- if ([400, 404, 409, 422].includes(error.status)) {
411
+ }
412
+ else {
413
+ // 複数エラーは箇条書き
414
+ const bullets = list.map(e => `- ${e.code !== '' ? `${e.code}: ` : ''}${e.description}`).join(descIndentJoin);
415
+ ymlString += `
416
+ '${status}':
417
+ description: |${descIndentJoin}【エラー】${descIndentJoin}${bullets}
418
+ content:
419
+ application/json:
420
+ schema:
421
+ type: object
422
+ properties:`;
423
+ }
424
+ if ([400, 404, 409, 422].includes(status)) {
395
425
  ymlString += `
396
426
  errorCode:
397
427
  type: string
@@ -400,13 +430,13 @@ class ResponseType extends ReqResType_1.default {
400
430
  type: string
401
431
  description: エラーメッセージ`;
402
432
  }
403
- else if (error.status === 401) {
433
+ else if (status === 401) {
404
434
  ymlString += `
405
435
  message:
406
436
  type: string
407
437
  description: Authentication expired. Please login again.`;
408
438
  }
409
- else if (error.status === 500) {
439
+ else if (status === 500) {
410
440
  ymlString += `
411
441
  message:
412
442
  type: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "2.0.105",
3
+ "version": "2.0.108",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
@@ -424,16 +424,49 @@ export class ResponseType extends ReqResType {
424
424
  code: '',
425
425
  description: 'サーバー内部エラー(予期せぬエラー)'
426
426
  })
427
- for (const error of errorList) {
428
- ymlString += `
429
- '${error.code}':
430
- description: 【エラー】${error.description}
427
+
428
+ // statusごとにグルーピング
429
+ const grouped: { [status: number]: IError[] } = {};
430
+ for (const e of errorList) {
431
+ if (grouped[e.status] === undefined) {
432
+ grouped[e.status] = [];
433
+ }
434
+ grouped[e.status].push(e);
435
+ }
436
+
437
+ // 出力順(存在するものだけ出す)
438
+ const statusOrder: Array<IError['status']> = [400, 401, 404, 409, 422, 500];
439
+
440
+ for (const status of statusOrder) {
441
+ const list = grouped[status];
442
+ if (!list || list.length === 0) { continue; }
443
+
444
+ const descIndentJoin = '\n ';
445
+
446
+ if (list.length === 1) {
447
+ // 単一エラーは1行説明
448
+ ymlString += `
449
+ '${status}':
450
+ description: 【エラー】${list[0].description}
431
451
  content:
432
452
  application/json:
433
453
  schema:
434
454
  type: object
435
455
  properties:`;
436
- if ([400, 404, 409, 422].includes(error.status)) {
456
+ } else {
457
+ // 複数エラーは箇条書き
458
+ const bullets = list.map(e => `- ${e.code !== '' ? `${e.code}: ` : ''}${e.description}`).join(descIndentJoin);
459
+ ymlString += `
460
+ '${status}':
461
+ description: |${descIndentJoin}【エラー】${descIndentJoin}${bullets}
462
+ content:
463
+ application/json:
464
+ schema:
465
+ type: object
466
+ properties:`;
467
+ }
468
+
469
+ if ([400, 404, 409, 422].includes(status)) {
437
470
  ymlString += `
438
471
  errorCode:
439
472
  type: string
@@ -441,12 +474,12 @@ export class ResponseType extends ReqResType {
441
474
  errorMessage:
442
475
  type: string
443
476
  description: エラーメッセージ`;
444
- } else if (error.status === 401) {
477
+ } else if (status === 401) {
445
478
  ymlString += `
446
479
  message:
447
480
  type: string
448
481
  description: Authentication expired. Please login again.`;
449
- } else if (error.status === 500) {
482
+ } else if (status === 500) {
450
483
  ymlString += `
451
484
  message:
452
485
  type: string