pg-mvc-service 1.0.14 → 1.0.16

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 CHANGED
@@ -24,7 +24,7 @@ const EncryptClient_1 = require("./clients/EncryptClient");
24
24
  const PoolManager_1 = __importDefault(require("./PoolManager"));
25
25
  class Service {
26
26
  get Method() { return this.method; }
27
- get Endpoint() { return this.endpoint; }
27
+ get Endpoint() { return this.endpoint + this.request.paramPath; }
28
28
  get ApiCode() { return this.apiCode; }
29
29
  get Summary() { return `${this.ApiCode !== '' ? this.apiCode + ': ' : ''}${this.summary}`; }
30
30
  get ApiUserAvailable() { return this.apiUserAvailable; }
@@ -21,12 +21,6 @@ const createSwagger = (services, name, url, params = []) => {
21
21
  endpontSwaggerYml[service.Endpoint] = {};
22
22
  }
23
23
  let yml = "";
24
- const splitEndpont = service.Endpoint.split('/');
25
- let tagName = splitEndpont[0];
26
- if (tagName === '' && splitEndpont.length > 1) {
27
- tagName = splitEndpont[1];
28
- ;
29
- }
30
24
  const apiTags = service.Tags;
31
25
  if (apiTags.length > 0) {
32
26
  tags = [...tags, ...apiTags];
@@ -38,8 +32,8 @@ const createSwagger = (services, name, url, params = []) => {
38
32
  yml += ` summary: ${service.Summary}\n`;
39
33
  const croneParams = [...params];
40
34
  for (const path of service.Endpoint.split('/')) {
41
- if (path.startsWith(':')) {
42
- const key = path.replace(':', '');
35
+ if (path.startsWith('{') && path.endsWith('}')) {
36
+ const key = path.replace('{', '').replace('}', '');
43
37
  croneParams.push({
44
38
  in: 'path',
45
39
  name: key,
@@ -82,7 +76,7 @@ tags:\n`;
82
76
  }
83
77
  swaggerInfo += 'paths:\n';
84
78
  for (const keyEndpoint in endpontSwaggerYml) {
85
- swaggerInfo += ` ${keyEndpoint.replace(/\/:([^\/]+)/g, '/{$1}')}:\n`;
79
+ swaggerInfo += ` ${keyEndpoint}:\n`;
86
80
  setYmlByMethod('GET', endpontSwaggerYml[keyEndpoint]);
87
81
  setYmlByMethod('POST', endpontSwaggerYml[keyEndpoint]);
88
82
  setYmlByMethod('PUT', endpontSwaggerYml[keyEndpoint]);
@@ -50,7 +50,10 @@ class RequestType extends ReqResType_1.default {
50
50
  INVALID_ENUM: '{property}は{enums}のいずれかの値で入力してください。({value})'
51
51
  };
52
52
  this.ERROR_MESSAGE = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
53
- this.paramProperties = {};
53
+ this.paramProperties = [];
54
+ }
55
+ get paramPath() {
56
+ return this.paramProperties.map(property => `/{${property.key}}`).join("");
54
57
  }
55
58
  get Params() {
56
59
  var _a;
@@ -87,11 +90,12 @@ class RequestType extends ReqResType_1.default {
87
90
  this.params = {};
88
91
  if (request.params !== undefined) {
89
92
  for (const [key, value] of Object.entries(request.params)) {
90
- const property = this.paramProperties[key];
91
- if (property === undefined) {
93
+ const index = this.paramProperties.findIndex(property => property.key === key);
94
+ if (index === -1) {
92
95
  throw new Error(`${key} is not set in paramProperties.`);
93
96
  }
94
- this.paramProperties[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${property.pathIndex})`], false);
97
+ const property = this.paramProperties[index];
98
+ this.params[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${index})`], false);
95
99
  }
96
100
  }
97
101
  this.params = (_a = request.params) !== null && _a !== void 0 ? _a : {};
package/index.d.ts CHANGED
@@ -85,7 +85,7 @@ declare module 'pg-mvc-service' {
85
85
  constructor();
86
86
 
87
87
  protected properties: { [key: string]: PropertyType; };
88
- protected paramProperties: { [key: string]: (PrimitiveType | EnumType) & { pathIndex: number }; };
88
+ protected paramProperties: Array<(PrimitiveType | EnumType) & { key: string }>;
89
89
  protected readonly ERROR_MESSAGE: ErrorMessageType;
90
90
 
91
91
  protected throwException(code: string, message: string): never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-mvc-service",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/n-daira/npm-pack_mvc-service#readme",
6
6
  "bugs": {
package/src/Service.ts CHANGED
@@ -16,7 +16,7 @@ export class Service {
16
16
  protected readonly method: MethodType = 'GET';
17
17
  get Method(): MethodType { return this.method; }
18
18
  protected readonly endpoint: string = '';
19
- get Endpoint(): string { return this.endpoint; }
19
+ get Endpoint(): string { return this.endpoint + this.request.paramPath; }
20
20
  protected readonly apiCode: string = '';
21
21
  get ApiCode(): string { return this.apiCode; }
22
22
  protected readonly summary: string = '';
@@ -31,12 +31,6 @@ export const createSwagger = (services: Service[], name: string, url: string, pa
31
31
  }
32
32
  let yml = "";
33
33
 
34
- const splitEndpont = service.Endpoint.split('/');
35
- let tagName = splitEndpont[0];
36
- if (tagName === '' && splitEndpont.length > 1) {
37
- tagName = splitEndpont[1];;
38
- }
39
-
40
34
  const apiTags = service.Tags;
41
35
  if (apiTags.length > 0) {
42
36
  tags = [ ...tags, ...apiTags];
@@ -49,8 +43,8 @@ export const createSwagger = (services: Service[], name: string, url: string, pa
49
43
 
50
44
  const croneParams = [...params];
51
45
  for (const path of service.Endpoint.split('/')) {
52
- if (path.startsWith(':')) {
53
- const key = path.replace(':', '');
46
+ if (path.startsWith('{') && path.endsWith('}')) {
47
+ const key = path.replace('{', '').replace('}', '');
54
48
  croneParams.push({
55
49
  in: 'path',
56
50
  name: key,
@@ -98,7 +92,7 @@ tags:\n`;
98
92
  swaggerInfo += 'paths:\n'
99
93
 
100
94
  for (const keyEndpoint in endpontSwaggerYml) {
101
- swaggerInfo += ` ${keyEndpoint.replace(/\/:([^\/]+)/g, '/{$1}')}:\n`;
95
+ swaggerInfo += ` ${keyEndpoint}:\n`;
102
96
 
103
97
  setYmlByMethod('GET', endpontSwaggerYml[keyEndpoint]);
104
98
  setYmlByMethod('POST', endpontSwaggerYml[keyEndpoint]);
@@ -65,9 +65,10 @@ export class RequestType extends ReqResType {
65
65
  }
66
66
  protected readonly ERROR_MESSAGE: ErrorMessageType = process.env.TZ === 'Asia/Tokyo' ? this.ERROR_MESSAGE_JAPAN : this.ERROR_MESSAGE_ENGLISH;
67
67
 
68
- protected paramProperties: {
69
- [key: string]: (PrimitiveType | EnumType) & { pathIndex: number };
70
- } = {};
68
+ protected paramProperties: Array<(PrimitiveType | EnumType) & { key: string }> = []
69
+ get paramPath(): string {
70
+ return this.paramProperties.map(property => `/{${property.key}}`).join("");
71
+ }
71
72
 
72
73
  private params?: {[key: string]: any};
73
74
  get Params(): {[key: string]: any} {
@@ -106,11 +107,12 @@ export class RequestType extends ReqResType {
106
107
  this.params = {};
107
108
  if (request.params !== undefined) {
108
109
  for (const [key, value] of Object.entries(request.params)) {
109
- const property = this.paramProperties[key];
110
- if (property === undefined) {
110
+ const index = this.paramProperties.findIndex(property => property.key === key);
111
+ if (index === -1) {
111
112
  throw new Error(`${key} is not set in paramProperties.`);
112
113
  }
113
- this.paramProperties[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${property.pathIndex})`], false);
114
+ const property = this.paramProperties[index];
115
+ this.params[key] = this.convertValue(property.type, value, [key, `(pathIndex: ${index})`], false);
114
116
  }
115
117
  }
116
118
  this.params = request.params ?? {};