ng2-rest-swagger-generator 18.0.17 → 18.0.18

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/lib/helpers.js CHANGED
@@ -1,28 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HelpersSwagger = void 0;
4
- var tslib_1 = require("tslib");
5
- var tnp_core_1 = require("tnp-core");
6
- var tnp_core_2 = require("tnp-core");
7
- var tnp_helpers_1 = require("tnp-helpers");
8
- var HelpersSwagger = /** @class */ (function (_super) {
9
- tslib_1.__extends(HelpersSwagger, _super);
10
- function HelpersSwagger() {
11
- return _super !== null && _super.apply(this, arguments) || this;
12
- }
13
- HelpersSwagger.preparePaths = function (apis, outputBase) {
14
- this.output = "".concat(process.cwd(), "/").concat(outputBase);
15
- this.apis = apis;
4
+ const tnp_core_1 = require("tnp-core");
5
+ const tnp_core_2 = require("tnp-core");
6
+ const tnp_helpers_1 = require("tnp-helpers");
7
+ class HelpersSwagger extends tnp_core_2.CoreHelpers {
8
+ static SYMBOL = {
9
+ INDEX_SWG: Symbol(),
10
+ OUTPUT_FOLDER: Symbol()
16
11
  };
17
- HelpersSwagger.prepareModel = function (swg, indexSwg, isHttpsEnable) {
12
+ static output;
13
+ static apis;
14
+ static preparePaths(apis, outputBase) {
15
+ this.output = `${process.cwd()}/${outputBase}`;
16
+ this.apis = apis;
17
+ }
18
+ static prepareModel(swg, indexSwg, isHttpsEnable) {
18
19
  swg[this.SYMBOL.INDEX_SWG] = indexSwg;
19
- swg.host = swg.host && (isHttpsEnable ? 'https' : 'http') + "://".concat(swg.host.replace(/:[0-9]*/g, ''));
20
+ swg.host = swg.host && (isHttpsEnable ? 'https' : 'http') + `://${swg.host.replace(/:[0-9]*/g, '')}`;
20
21
  if (!swg.basePath) {
21
22
  swg.basePath = '';
22
23
  }
23
- };
24
+ }
24
25
  //#region @backend
25
- HelpersSwagger.recreateIfNotExist = function (pathToFileOrFolder, content) {
26
+ static recreateIfNotExist(pathToFileOrFolder, content) {
26
27
  if (tnp_core_1._.isUndefined(content)) {
27
28
  if (tnp_core_1.fse.existsSync(pathToFileOrFolder)) {
28
29
  tnp_helpers_1.Helpers.remove(pathToFileOrFolder);
@@ -33,7 +34,7 @@ var HelpersSwagger = /** @class */ (function (_super) {
33
34
  if (tnp_core_1.fse.existsSync(pathToFileOrFolder)) {
34
35
  tnp_core_1.fse.unlinkSync(pathToFileOrFolder);
35
36
  }
36
- var dirName = tnp_core_1.path.dirname(pathToFileOrFolder);
37
+ const dirName = tnp_core_1.path.dirname(pathToFileOrFolder);
37
38
  if (!tnp_core_1.fse.existsSync(dirName)) {
38
39
  tnp_core_1.fse.mkdirpSync(dirName);
39
40
  }
@@ -41,116 +42,96 @@ var HelpersSwagger = /** @class */ (function (_super) {
41
42
  encoding: 'utf8'
42
43
  });
43
44
  }
44
- };
45
- Object.defineProperty(HelpersSwagger, "serviceFromTag", {
46
- //#endregion
47
- get: function () {
48
- var self = this;
49
- return {
50
- allClassNames: function () {
51
- var names = [];
52
- self.apis.map(function (swg) {
53
- swg.tags.forEach(function (tag) {
54
- names.push(self.serviceFromTag.className(swg, tag));
55
- });
56
- });
57
- return names;
58
- },
59
- className: function (swg, tag) {
60
- var groupFolderName = self.groupFromJSON.folderName(swg);
61
- // console.log('groupFolderName', groupFolderName)
62
- var className = tnp_core_1._.upperFirst(tnp_core_1._.camelCase(tag.name)) + 'Service';
63
- return "".concat(groupFolderName).concat(className.replace(/\//g, ''));
64
- },
65
- absoluteFilePath: function (swg, tag) {
66
- return "".concat(self.absolutePath.PathFolder_services_groupName(swg), "/").concat(self.serviceFromTag.className(swg, tag), ".ts");
67
- }
68
- };
69
- },
70
- enumerable: false,
71
- configurable: true
72
- });
73
- Object.defineProperty(HelpersSwagger, "endpoints", {
74
- get: function () {
75
- var _this = this;
76
- return this.apis.map(function (swg) {
77
- return "".concat(_this.groupFromJSON.folderName(swg), ":'").concat(swg.host, "'");
78
- });
79
- },
80
- enumerable: false,
81
- configurable: true
82
- });
83
- Object.defineProperty(HelpersSwagger, "absolutePath", {
84
- get: function () {
85
- var self = this;
86
- return {
87
- get output() {
88
- return self.output;
89
- },
90
- get PathFile_index_ts() {
91
- var APIpath = self.output;
92
- return "".concat(APIpath, "/index.ts");
93
- },
94
- get PathFile_module_ts() {
95
- var APIpath = self.output;
96
- return "".concat(APIpath, "/module.ts");
97
- },
98
- get PathFolder_services() {
99
- var APIpath = self.output;
100
- return "".concat(APIpath, "/services");
101
- },
102
- get PathFile_services_index_ts() {
103
- return "".concat(self.absolutePath.PathFolder_services, "/index.ts");
104
- },
105
- PathFolder_services_groupName: function (swg) {
106
- var groupFolderName = self.groupFromJSON.folderName(swg);
107
- // console.log('groupFolderName', groupFolderName)
108
- return "".concat(self.absolutePath.PathFolder_services, "/").concat(groupFolderName);
109
- },
110
- PathFile_services_groupName_index_ts: function (swg) {
111
- return "".concat(self.absolutePath.PathFolder_services_groupName(swg), "/index.ts");
112
- },
113
- PathFile_services_groupNAme_serviceName_ts: function (swg, tag) {
114
- var serviceFileName = self.serviceFromTag.className(swg, tag);
115
- return "".concat(self.absolutePath.PathFolder_services_groupName(swg), "/").concat(serviceFileName, ".ts");
116
- }
117
- };
118
- },
119
- enumerable: false,
120
- configurable: true
121
- });
122
- Object.defineProperty(HelpersSwagger, "groupFromJSON", {
123
- get: function () {
124
- var self = this;
125
- return {
126
- get allGroupNames() {
127
- var names = [];
128
- self.apis.map(function (swg) {
129
- names.push(self.groupFromJSON.folderName(swg));
45
+ }
46
+ //#endregion
47
+ static get serviceFromTag() {
48
+ const self = this;
49
+ return {
50
+ allClassNames() {
51
+ const names = [];
52
+ self.apis.map(swg => {
53
+ swg.tags.forEach(tag => {
54
+ names.push(self.serviceFromTag.className(swg, tag));
130
55
  });
131
- return names;
132
- },
133
- folderName: function (swg) {
134
- var basePath = swg.basePath;
135
- var index = swg[self.SYMBOL.INDEX_SWG];
136
- return tnp_core_1._.upperFirst(tnp_core_1._.camelCase(basePath.trim() === '' ? "json".concat(index) : basePath));
137
- }
138
- };
139
- },
140
- enumerable: false,
141
- configurable: true
142
- });
143
- HelpersSwagger.findTags = function (swg) {
144
- var tags = [];
145
- Object.keys(swg.paths).forEach(function (p) {
146
- Object.keys(swg.paths[p]).forEach(function (m) {
147
- var a = swg.paths[p][m];
56
+ });
57
+ return names;
58
+ },
59
+ className(swg, tag) {
60
+ const groupFolderName = self.groupFromJSON.folderName(swg);
61
+ // console.log('groupFolderName', groupFolderName)
62
+ const className = tnp_core_1._.upperFirst(tnp_core_1._.camelCase(tag.name)) + 'Service';
63
+ return `${groupFolderName}${className.replace(/\//g, '')}`;
64
+ },
65
+ absoluteFilePath(swg, tag) {
66
+ return `${self.absolutePath.PathFolder_services_groupName(swg)}/${self.serviceFromTag.className(swg, tag)}.ts`;
67
+ }
68
+ };
69
+ }
70
+ static get endpoints() {
71
+ return this.apis.map(swg => {
72
+ return `${this.groupFromJSON.folderName(swg)}:'${swg.host}'`;
73
+ });
74
+ }
75
+ static get absolutePath() {
76
+ const self = this;
77
+ return {
78
+ get output() {
79
+ return self.output;
80
+ },
81
+ get PathFile_index_ts() {
82
+ const APIpath = self.output;
83
+ return `${APIpath}/index.ts`;
84
+ },
85
+ get PathFile_module_ts() {
86
+ const APIpath = self.output;
87
+ return `${APIpath}/module.ts`;
88
+ },
89
+ get PathFolder_services() {
90
+ const APIpath = self.output;
91
+ return `${APIpath}/services`;
92
+ },
93
+ get PathFile_services_index_ts() {
94
+ return `${self.absolutePath.PathFolder_services}/index.ts`;
95
+ },
96
+ PathFolder_services_groupName(swg) {
97
+ const groupFolderName = self.groupFromJSON.folderName(swg);
98
+ // console.log('groupFolderName', groupFolderName)
99
+ return `${self.absolutePath.PathFolder_services}/${groupFolderName}`;
100
+ },
101
+ PathFile_services_groupName_index_ts(swg) {
102
+ return `${self.absolutePath.PathFolder_services_groupName(swg)}/index.ts`;
103
+ },
104
+ PathFile_services_groupNAme_serviceName_ts(swg, tag) {
105
+ const serviceFileName = self.serviceFromTag.className(swg, tag);
106
+ return `${self.absolutePath.PathFolder_services_groupName(swg)}/${serviceFileName}.ts`;
107
+ }
108
+ };
109
+ }
110
+ static get groupFromJSON() {
111
+ const self = this;
112
+ return {
113
+ get allGroupNames() {
114
+ const names = [];
115
+ self.apis.map(swg => {
116
+ names.push(self.groupFromJSON.folderName(swg));
117
+ });
118
+ return names;
119
+ },
120
+ folderName(swg) {
121
+ const basePath = swg.basePath;
122
+ const index = swg[self.SYMBOL.INDEX_SWG];
123
+ return tnp_core_1._.upperFirst(tnp_core_1._.camelCase(basePath.trim() === '' ? `json${index}` : basePath));
124
+ }
125
+ };
126
+ }
127
+ static findTags(swg) {
128
+ const tags = [];
129
+ Object.keys(swg.paths).forEach(p => {
130
+ Object.keys(swg.paths[p]).forEach(m => {
131
+ const a = swg.paths[p][m];
148
132
  if (tnp_core_1._.isArray(a.tags)) {
149
- a.tags.forEach(function (tag) {
150
- if (tags.filter(function (_a) {
151
- var name = _a.name;
152
- return name === tag;
153
- }).length === 0) { // @ts-ignore
133
+ a.tags.forEach(tag => {
134
+ if (tags.filter(({ name }) => name === tag).length === 0) { // @ts-ignore
154
135
  tags.push({ name: tag });
155
136
  }
156
137
  });
@@ -158,65 +139,62 @@ var HelpersSwagger = /** @class */ (function (_super) {
158
139
  });
159
140
  });
160
141
  return tags;
161
- };
142
+ }
162
143
  /**
163
144
  * To generate get/books/{id} => get_books__id_
164
145
  */
165
- HelpersSwagger.cleanPath = function (path) {
146
+ static cleanPath(path) {
166
147
  return path.replace(/{/g, "_").replace(/}/g, "_").replace(/\//g, "_").replace(/-/g, "_");
167
- };
168
- HelpersSwagger.cleanPathModel = function (pathModel) {
148
+ }
149
+ static cleanPathModel(pathModel) {
169
150
  return pathModel.replace(/\/{/g, '/:').replace(/}/g, '');
170
- };
171
- HelpersSwagger.swaggerTypeToJS = function (type, itemsType) {
172
- if (itemsType === void 0) { itemsType = 'any'; }
151
+ }
152
+ static swaggerTypeToJS(type, itemsType = 'any') {
173
153
  return (type === 'integer') ? 'number'
174
- : (type === 'array') ? !itemsType ? 'any' : "".concat(this.swaggerTypeToJS(itemsType), "[]")
154
+ : (type === 'array') ? !itemsType ? 'any' : `${this.swaggerTypeToJS(itemsType)}[]`
175
155
  : (type === 'file') ? 'any' : type;
176
- };
177
- HelpersSwagger.getObjectDefinition = function (ref, swg, deep) {
178
- var _this = this;
179
- if (deep === void 0) { deep = 0; }
156
+ }
157
+ static getObjectDefinition(ref, swg, deep = 0) {
180
158
  if (deep == 1)
181
159
  return '';
182
160
  if (!ref) {
183
161
  console.log('Bad json $ref inside swagger');
184
162
  return '';
185
163
  }
186
- var res = '';
164
+ let res = '';
187
165
  ref = ref.replace('#/', '').replace(/\//g, '.');
188
- var obj = tnp_core_1._.get(swg, ref);
166
+ let obj = tnp_core_1._.get(swg, ref);
189
167
  // if (obj.properties.viaAgentViaGroupDTOs && !getObjectDefinition.prototype.once) {
190
168
  // console.log('============================================================')
191
169
  // console.log('obj', obj)
192
170
  // console.log('------------------------------------------------------------')
193
171
  // getObjectDefinition.prototype.once = true;
194
- tnp_core_1._.forOwn(obj.properties, function (v, k) {
172
+ tnp_core_1._.forOwn(obj.properties, (v, k) => {
195
173
  // console.log(obj)
196
174
  if (v.$ref && typeof v.$ref === "string") {
197
- res += k + ":{" + _this.getObjectDefinition(v.$ref, swg, deep++) + "};\n";
175
+ res += k + ":{" + this.getObjectDefinition(v.$ref, swg, deep++) + "};\n";
198
176
  }
199
177
  else if (v.schema && v.schema.$ref && typeof v.schema.$ref === "string") {
200
- res += k + ":{" + _this.getObjectDefinition(v.schema.$ref, swg, deep++) + "};\n";
178
+ res += k + ":{" + this.getObjectDefinition(v.schema.$ref, swg, deep++) + "};\n";
201
179
  }
202
180
  else if (v.items && v.items.$ref && typeof v.items.$ref === "string" && v.type && v.type === 'array') {
203
- res += k + ":{" + _this.getObjectDefinition(v.items.$ref, swg, deep++) + "}[];\n";
181
+ res += k + ":{" + this.getObjectDefinition(v.items.$ref, swg, deep++) + "}[];\n";
204
182
  // console.log('make love here')
205
183
  }
206
184
  else if (v.items && v.items.$ref && typeof v.items.$ref === "string") {
207
- res += k + ":{" + _this.getObjectDefinition(v.items.$ref, swg, deep++) + "};\n";
185
+ res += k + ":{" + this.getObjectDefinition(v.items.$ref, swg, deep++) + "};\n";
208
186
  }
209
187
  else {
210
- var isRequired = (obj.required && obj.required instanceof Array && obj.required.filter(function (o) { return o === k; }).length > 0);
211
- var type = (v.enum && v.enum instanceof Array && v.enum.length > 0)
212
- ? v.enum.map(function (e) { return '"' + e + '"'; }).join('|') : _this.swaggerTypeToJS(v.type, v.items ? v.items.type : 'any');
188
+ let isRequired = (obj.required && obj.required instanceof Array && obj.required.filter(o => o === k).length > 0);
189
+ let type = (v.enum && v.enum instanceof Array && v.enum.length > 0)
190
+ ? v.enum.map(e => '"' + e + '"').join('|') : this.swaggerTypeToJS(v.type, v.items ? v.items.type : 'any');
213
191
  res += k + (!isRequired ? '?' : "") + ":" + type + ";\n";
214
192
  }
215
193
  });
216
194
  // console.log('res', res)
217
195
  // }
218
196
  return res;
219
- };
197
+ }
220
198
  /**
221
199
  * private pathes = {
222
200
  * get_all_companies: new SimpleResource<
@@ -225,21 +203,20 @@ var HelpersSwagger = /** @class */ (function (_super) {
225
203
  * string, A, TA, RP extends Object, QP extends Rest.UrlParams>(endpoint, model)
226
204
  * }
227
205
  */
228
- HelpersSwagger.getAngularPrivatePathesByTag = function (swg, tag) {
229
- var _this = this;
230
- var res = [];
231
- var base = swg.basePath.replace('/', '');
232
- var pathes = {};
233
- tnp_core_1._.forOwn(swg.paths, function (v, k) {
234
- tnp_core_1._.forOwn(v, function (v2, k2) {
235
- if (tnp_core_1._.isArray(v2.tags) && v2.tags.filter(function (f) { return f === tag.name; }).length > 0) {
236
- var resp = v2.responses['200'] && v2.responses['200'].schema;
206
+ static getAngularPrivatePathesByTag(swg, tag) {
207
+ let res = [];
208
+ let base = swg.basePath.replace('/', '');
209
+ let pathes = {};
210
+ tnp_core_1._.forOwn(swg.paths, (v, k) => {
211
+ tnp_core_1._.forOwn(v, (v2, k2) => {
212
+ if (tnp_core_1._.isArray(v2.tags) && v2.tags.filter(f => f === tag.name).length > 0) {
213
+ let resp = v2.responses['200'] && v2.responses['200'].schema;
237
214
  // if (resp) {
238
215
  // TODO response handling
239
216
  // console.log('resp',resp);
240
217
  if (pathes[k] === void 0)
241
218
  pathes[k] = {}; // @ts-ignore
242
- var type = _this.getResponseType(resp, swg);
219
+ let type = this.getResponseType(resp, swg);
243
220
  if (type.length > 3 && type.charAt(type.length - 1) === ']' && type.charAt(type.length - 2) === '['
244
221
  && !pathes[k]['array']) {
245
222
  pathes[k]['array'] = type;
@@ -251,12 +228,12 @@ var HelpersSwagger = /** @class */ (function (_super) {
251
228
  }
252
229
  });
253
230
  });
254
- var pathResources = [];
255
- tnp_core_1._.forOwn(pathes, function (v, p) {
231
+ let pathResources = [];
232
+ tnp_core_1._.forOwn(pathes, (v, p) => {
256
233
  // console.log(`${p} - ${JSON.stringify(v)}`);
257
234
  pathResources.push({
258
- clean_path: _this.cleanPath(p),
259
- model: _this.cleanPathModel(p),
235
+ clean_path: this.cleanPath(p),
236
+ model: this.cleanPathModel(p),
260
237
  endpoint: swg.basePath,
261
238
  singleModelType: !v['single'] ? 'any' : v['single'],
262
239
  multipleModelType: !v['array'] ? 'any' : v['array'],
@@ -264,11 +241,11 @@ var HelpersSwagger = /** @class */ (function (_super) {
264
241
  pathParamsType: 'any'
265
242
  });
266
243
  });
267
- pathResources.forEach(function (p) {
268
- res.push("".concat(p.clean_path, ": new SimpleResource<\n").concat(p.singleModelType, ",\n").concat(p.multipleModelType, "\n>( Ng2RestGenModule.enpointUrls.").concat(_this.groupFromJSON.folderName(swg), ", '").concat(p.model, "' )"));
244
+ pathResources.forEach(p => {
245
+ res.push(`${p.clean_path}: new SimpleResource<\n${p.singleModelType},\n${p.multipleModelType}\n>( Ng2RestGenModule.enpointUrls.${this.groupFromJSON.folderName(swg)}, '${p.model}' )`);
269
246
  });
270
- return "private pathes = { \n".concat(res.join(',\n'), "\n};");
271
- };
247
+ return `private pathes = { \n${res.join(',\n')}\n};`;
248
+ }
272
249
  /*
273
250
  schema": {
274
251
  "type": "array",
@@ -281,8 +258,8 @@ var HelpersSwagger = /** @class */ (function (_super) {
281
258
  "$ref": "#/definitions/CompanyDTO"
282
259
  }
283
260
  */
284
- HelpersSwagger.getResponseType = function (o, swg) {
285
- var res = '{} | any';
261
+ static getResponseType(o, swg) {
262
+ let res = '{} | any';
286
263
  if (o && o.$ref && typeof o.$ref === 'string' && o.$ref.trim() !== '') {
287
264
  res = "{" + this.getObjectDefinition(o.$ref, swg) + "}";
288
265
  // console.log('I am object', o.$ref)
@@ -296,104 +273,98 @@ var HelpersSwagger = /** @class */ (function (_super) {
296
273
  // console.log('type', res)
297
274
  // console.log('------------------------------------------------------------')
298
275
  return res;
299
- };
276
+ }
300
277
  //#region @backend
301
278
  /**
302
279
  * public getAllCompanies = ({ params },{ queryparams1 }) => this.pathes.get_all_companies.model(params).get(queryparams),
303
280
  * public getAllCompanies = ({ params },{ queryparams1 },{body}) => this.pathes.get_all_companies.model(params).put(body,queryparams)
304
281
  */
305
- HelpersSwagger.getServicesMethod = function (swg, tag) {
306
- var _this = this;
307
- var methods = [];
308
- for (var urlpath in swg.paths) {
309
- var _loop_1 = function (methodhttp) {
310
- var m = swg.paths[urlpath][methodhttp];
311
- if (tnp_core_1._.isArray(m.tags) && m.tags.filter(function (t) { return t === tag.name; }).length === 1) {
312
- var sm_1 = {};
313
- sm_1.summary = tnp_core_1._.camelCase(m.operationId ? m.operationId : m.summary);
314
- sm_1.method = methodhttp; // <Models.Morphi.Rest.HttpMethod>methodhttp;
315
- sm_1.path_cleand = this_1.cleanPath(urlpath);
282
+ static getServicesMethod(swg, tag) {
283
+ let methods = [];
284
+ for (let urlpath in swg.paths) {
285
+ for (let methodhttp in swg.paths[urlpath]) {
286
+ let m = swg.paths[urlpath][methodhttp];
287
+ if (tnp_core_1._.isArray(m.tags) && m.tags.filter(t => t === tag.name).length === 1) {
288
+ let sm = {};
289
+ sm.summary = tnp_core_1._.camelCase(m.operationId ? m.operationId : m.summary);
290
+ sm.method = methodhttp; // <Models.Morphi.Rest.HttpMethod>methodhttp;
291
+ sm.path_cleand = this.cleanPath(urlpath);
316
292
  // console.log('sm.path_cleand', sm.path_cleand)
317
- sm_1.params = {};
318
- sm_1.params.query = [];
319
- sm_1.params.path = [];
320
- sm_1.params.body = [];
321
- sm_1.comment = '';
293
+ sm.params = {};
294
+ sm.params.query = [];
295
+ sm.params.path = [];
296
+ sm.params.body = [];
297
+ sm.comment = '';
322
298
  // QUICKFIX
323
299
  if (m.responses && m.responses['200'] && m.responses['200'].schema // @ts-ignore
324
300
  && m.responses['200'].schema.type && m.responses['200'].schema.type === 'array') {
325
- sm_1.isArray = true;
301
+ sm.isArray = true;
326
302
  }
327
303
  if (m.parameters)
328
- m.parameters.forEach(function (param) {
329
- var ptypeExitst = (param.type && param.type.length > 0);
330
- sm_1.comment += ('*' + (ptypeExitst ? " { ".concat(param.type, " } ") : ' ') + "".concat(param.name, " (").concat(param.description, ")") + "\n");
304
+ m.parameters.forEach(param => {
305
+ let ptypeExitst = (param.type && param.type.length > 0);
306
+ sm.comment += ('*' + (ptypeExitst ? ` { ${param.type} } ` : ' ') + `${param.name} (${param.description})` + "\n");
331
307
  if (param.in === 'body') {
332
- var type = void 0;
308
+ let type;
333
309
  if (param.schema.items && param.schema.items.$ref && param.schema.type == 'array') {
334
- type = "{" + _this.getObjectDefinition(param.schema.items.$ref, swg) + "}[]";
310
+ type = "{" + this.getObjectDefinition(param.schema.items.$ref, swg) + "}[]";
335
311
  }
336
312
  else {
337
- type = (param.schema.$ref ? ("{" + _this.getObjectDefinition(param.schema.$ref, swg) + "}")
338
- : _this.swaggerTypeToJS(param.type));
313
+ type = (param.schema.$ref ? ("{" + this.getObjectDefinition(param.schema.$ref, swg) + "}")
314
+ : this.swaggerTypeToJS(param.type));
339
315
  }
340
316
  // @ts-ignore
341
- sm_1.params.body.push({
317
+ sm.params.body.push({
342
318
  name: param.name,
343
- type: type,
319
+ type,
344
320
  required: param.required,
345
321
  isObject: true
346
322
  });
347
323
  }
348
324
  else {
349
- if (!tnp_core_1._.isArray(sm_1.params[param.in])) {
350
- sm_1.params[param.in] = [];
325
+ if (!tnp_core_1._.isArray(sm.params[param.in])) {
326
+ sm.params[param.in] = [];
351
327
  }
352
- sm_1.params[param.in].push({
328
+ sm.params[param.in].push({
353
329
  name: param.name,
354
- type: _this.swaggerTypeToJS(param.type),
330
+ type: this.swaggerTypeToJS(param.type),
355
331
  required: param.required
356
332
  });
357
333
  }
358
334
  });
359
- methods.push(sm_1);
335
+ methods.push(sm);
360
336
  }
361
- };
362
- var this_1 = this;
363
- for (var methodhttp in swg.paths[urlpath]) {
364
- _loop_1(methodhttp);
365
337
  }
366
338
  }
367
339
  return methods;
368
- };
340
+ }
369
341
  //#endregion
370
342
  //#region @backend
371
- HelpersSwagger.getAngularServicesMethods = function (swg, tag) {
372
- var _this = this;
373
- var res = '';
374
- var methods = this.getServicesMethod(swg, tag);
375
- methods.forEach(function (m) {
376
- var neededParams = {
343
+ static getAngularServicesMethods(swg, tag) {
344
+ let res = '';
345
+ let methods = this.getServicesMethod(swg, tag);
346
+ methods.forEach(m => {
347
+ let neededParams = {
377
348
  path: (m.params && m.params.path && m.params.path.length > 0),
378
349
  query: (m.params && m.params.query && m.params.query.length > 0),
379
350
  body: (m.params && m.params.body && m.params.body.length > 0)
380
351
  };
381
- var paramsPath = neededParams.path // @ts-ignore
382
- ? m.params.path.map(function (p) { return p['joined'] = p.name + ':' + p.type; }).join(',') : '';
383
- var paramsQuery = neededParams.query // @ts-ignore
384
- ? m.params.query.map(function (p) { return p['joined'] = p.name + ':' + p.type; }).join(',') : '';
385
- var paramsBody = neededParams.body // @ts-ignore
386
- ? m.params.body.map(function (p) { return p['joined'] = p.name + ':' + p.type; }).join(',') : '';
387
- var paramPathNames = "{" + (neededParams.path // @ts-ignore
388
- ? m.params.path.map(function (p) { return p['joined'] = p.name; }).filter(function (d) { return d; }).join(',') : '') + '}';
389
- var paramQueryNames = "{" + (neededParams.query // @ts-ignore
390
- ? m.params.query.map(function (p) { return p['joined'] = p.name; }).filter(function (d) { return d; }).join(',') : '') + '}';
391
- var paramBodyNames = "{" + (neededParams.body // @ts-ignore
392
- ? m.params.body.map(function (p) { return p['joined'] = p.name; }).filter(function (d) { return d; }).join(',') : '') + '}';
393
- var method = m.method;
352
+ let paramsPath = neededParams.path // @ts-ignore
353
+ ? m.params.path.map(p => p['joined'] = p.name + ':' + p.type).join(',') : '';
354
+ let paramsQuery = neededParams.query // @ts-ignore
355
+ ? m.params.query.map(p => p['joined'] = p.name + ':' + p.type).join(',') : '';
356
+ let paramsBody = neededParams.body // @ts-ignore
357
+ ? m.params.body.map(p => p['joined'] = p.name + ':' + p.type).join(',') : '';
358
+ let paramPathNames = "{" + (neededParams.path // @ts-ignore
359
+ ? m.params.path.map(p => p['joined'] = p.name).filter(d => d).join(',') : '') + '}';
360
+ let paramQueryNames = "{" + (neededParams.query // @ts-ignore
361
+ ? m.params.query.map(p => p['joined'] = p.name).filter(d => d).join(',') : '') + '}';
362
+ let paramBodyNames = "{" + (neededParams.body // @ts-ignore
363
+ ? m.params.body.map(p => p['joined'] = p.name).filter(d => d).join(',') : '') + '}';
364
+ let method = m.method;
394
365
  if (m.isArray && m.method === 'get')
395
366
  method = 'query';
396
- var params = [paramsPath, paramsQuery, paramsBody].filter(function (d) { return d && d !== '{}'; }).join(',');
367
+ let params = [paramsPath, paramsQuery, paramsBody].filter(d => d && d !== '{}').join(',');
397
368
  // QUICKFIX change {object} to object in method
398
369
  // @ts-ignore
399
370
  if (neededParams.query && m.params.query.length === 1 && m.params.query[0].isObject) { // @ts-ignore
@@ -403,27 +374,24 @@ var HelpersSwagger = /** @class */ (function (_super) {
403
374
  if (neededParams.body && m.params.body.length === 1 && m.params.body[0].isObject) { // @ts-ignore
404
375
  paramBodyNames = paramBodyNames.match(new RegExp('[a-zA-Z]+', 'g'))[0];
405
376
  }
406
- var paramsName = [paramBodyNames, paramQueryNames].filter(function (d) { return d && d !== '{}'; }).map(function (d) { return '<any>' + d; }).join(',');
407
- var comment = m.comment ? ("/**" + '\n' +
408
- "".concat(m.comment.trim(), "\n */")) : '';
409
- res += ("".concat(comment, "\npublic") + _this.recreateSummary(m.summary) + '= (' + params + ') =>\nthis.pathes.'
410
- + m.path_cleand + "\n.model(".concat(paramPathNames, ") \n.").concat(method, " (").concat(paramsName, "); ") + "\n");
377
+ let paramsName = [paramBodyNames, paramQueryNames].filter(d => d && d !== '{}').map(d => '<any>' + d).join(',');
378
+ let comment = m.comment ? (`/**` + '\n' +
379
+ `${m.comment.trim()}
380
+ */`) : '';
381
+ res += (`${comment}
382
+ public` + this.recreateSummary(m.summary) + '= (' + params + ') =>\nthis.pathes.'
383
+ + m.path_cleand + `\n.model(${paramPathNames}) \n.${method} (${paramsName}); ` + "\n");
411
384
  });
412
385
  return res;
413
- };
414
- HelpersSwagger.recreateSummary = function (summary) {
386
+ }
387
+ //#endregion
388
+ static count1 = 0;
389
+ static recreateSummary(summary) {
415
390
  // if (!summary) {
416
391
  // return 'SummaryExample' + (count1++)
417
392
  // }
418
393
  return summary;
419
- };
420
- HelpersSwagger.SYMBOL = {
421
- INDEX_SWG: Symbol(),
422
- OUTPUT_FOLDER: Symbol()
423
- };
424
- //#endregion
425
- HelpersSwagger.count1 = 0;
426
- return HelpersSwagger;
427
- }(tnp_core_2.CoreHelpers));
394
+ }
395
+ }
428
396
  exports.HelpersSwagger = HelpersSwagger;
429
397
  //# sourceMappingURL=helpers.js.map