ng2-rest-swagger-generator 18.0.17 → 18.0.19
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/assets/shared/shared_folder_info.txt +1 -1
- package/generator.js +29 -31
- package/generator.js.map +1 -1
- package/index.js +15 -2
- package/index.js.map +1 -1
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/helpers.js +209 -241
- package/lib/helpers.js.map +1 -1
- package/lib/index._auto-generated_.d.ts +1 -0
- package/lib/index._auto-generated_.js.map +1 -1
- package/lib/index.js +15 -2
- package/lib/index.js.map +1 -1
- package/lib/models.js.map +1 -1
- package/migrations/index.js +15 -2
- package/migrations/index.js.map +1 -1
- package/migrations/migrations_index._auto-generated_.d.ts +1 -0
- package/migrations/migrations_index._auto-generated_.js.map +1 -1
- package/package.json +20 -76
- package/src.d.ts +1 -1
- package/start.js +11 -11
- package/start.js.map +1 -1
- package/template.js +68 -35
- package/template.js.map +1 -1
- package/tmp-environment.json +8 -412
- package/browser/package.json +0 -25
- package/taon.jsonc +0 -45
- package/websql/package.json +0 -25
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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') +
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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(
|
|
150
|
-
if (tags.filter(
|
|
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
|
-
|
|
146
|
+
static cleanPath(path) {
|
|
166
147
|
return path.replace(/{/g, "_").replace(/}/g, "_").replace(/\//g, "_").replace(/-/g, "_");
|
|
167
|
-
}
|
|
168
|
-
|
|
148
|
+
}
|
|
149
|
+
static cleanPathModel(pathModel) {
|
|
169
150
|
return pathModel.replace(/\/{/g, '/:').replace(/}/g, '');
|
|
170
|
-
}
|
|
171
|
-
|
|
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' :
|
|
154
|
+
: (type === 'array') ? !itemsType ? 'any' : `${this.swaggerTypeToJS(itemsType)}[]`
|
|
175
155
|
: (type === 'file') ? 'any' : type;
|
|
176
|
-
}
|
|
177
|
-
|
|
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
|
-
|
|
164
|
+
let res = '';
|
|
187
165
|
ref = ref.replace('#/', '').replace(/\//g, '.');
|
|
188
|
-
|
|
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,
|
|
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 + ":{" +
|
|
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 + ":{" +
|
|
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 + ":{" +
|
|
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 + ":{" +
|
|
185
|
+
res += k + ":{" + this.getObjectDefinition(v.items.$ref, swg, deep++) + "};\n";
|
|
208
186
|
}
|
|
209
187
|
else {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
? v.enum.map(
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
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
|
-
|
|
255
|
-
tnp_core_1._.forOwn(pathes,
|
|
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:
|
|
259
|
-
model:
|
|
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(
|
|
268
|
-
res.push(
|
|
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
|
|
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
|
-
|
|
285
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
|
|
301
|
+
sm.isArray = true;
|
|
326
302
|
}
|
|
327
303
|
if (m.parameters)
|
|
328
|
-
m.parameters.forEach(
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
|
|
308
|
+
let type;
|
|
333
309
|
if (param.schema.items && param.schema.items.$ref && param.schema.type == 'array') {
|
|
334
|
-
type = "{" +
|
|
310
|
+
type = "{" + this.getObjectDefinition(param.schema.items.$ref, swg) + "}[]";
|
|
335
311
|
}
|
|
336
312
|
else {
|
|
337
|
-
type = (param.schema.$ref ? ("{" +
|
|
338
|
-
:
|
|
313
|
+
type = (param.schema.$ref ? ("{" + this.getObjectDefinition(param.schema.$ref, swg) + "}")
|
|
314
|
+
: this.swaggerTypeToJS(param.type));
|
|
339
315
|
}
|
|
340
316
|
// @ts-ignore
|
|
341
|
-
|
|
317
|
+
sm.params.body.push({
|
|
342
318
|
name: param.name,
|
|
343
|
-
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(
|
|
350
|
-
|
|
325
|
+
if (!tnp_core_1._.isArray(sm.params[param.in])) {
|
|
326
|
+
sm.params[param.in] = [];
|
|
351
327
|
}
|
|
352
|
-
|
|
328
|
+
sm.params[param.in].push({
|
|
353
329
|
name: param.name,
|
|
354
|
-
type:
|
|
330
|
+
type: this.swaggerTypeToJS(param.type),
|
|
355
331
|
required: param.required
|
|
356
332
|
});
|
|
357
333
|
}
|
|
358
334
|
});
|
|
359
|
-
methods.push(
|
|
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
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
382
|
-
? m.params.path.map(
|
|
383
|
-
|
|
384
|
-
? m.params.query.map(
|
|
385
|
-
|
|
386
|
-
? m.params.body.map(
|
|
387
|
-
|
|
388
|
-
? m.params.path.map(
|
|
389
|
-
|
|
390
|
-
? m.params.query.map(
|
|
391
|
-
|
|
392
|
-
? m.params.body.map(
|
|
393
|
-
|
|
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
|
-
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|