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