ng2-rest-swagger-generator 21.0.18 → 21.0.20
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/package.json +1 -1
- package/browser-prod/package.json +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib-prod/build-info._auto-generated_.js +26 -14
- package/lib-prod/env/env.angular-node-app.js +66 -130
- package/lib-prod/env/env.docs-webapp.js +66 -130
- package/lib-prod/env/env.electron-app.js +66 -130
- package/lib-prod/env/env.mobile-app.js +66 -130
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +66 -130
- package/lib-prod/env/env.vscode-plugin.js +66 -130
- package/lib-prod/env/index.js +6 -6
- package/lib-prod/helpers.js +478 -365
- package/lib-prod/index._auto-generated_.js +5 -0
- package/lib-prod/index.js +1 -1
- package/lib-prod/migrations/index.js +2 -1
- package/lib-prod/migrations/migrations_index._auto-generated_.js +3 -0
- package/lib-prod/models.js +3 -0
- package/lib-prod/package.json +1 -1
- package/lib-prod.split-namespaces.json +2 -40
- package/package.json +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
package/lib-prod/helpers.js
CHANGED
|
@@ -1,229 +1,289 @@
|
|
|
1
|
-
import { path, fse, ___NS__camelCase, ___NS__forOwn, ___NS__get, ___NS__isArray, ___NS__isUndefined, ___NS__upperFirst } from
|
|
2
|
-
import { Helpers__NS__remove } from
|
|
3
|
-
class HelpersSwagger {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 = "";
|
|
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
|
+
export class HelpersSwagger {
|
|
4
|
+
static {
|
|
5
|
+
this.SYMBOL = {
|
|
6
|
+
INDEX_SWG: Symbol(),
|
|
7
|
+
OUTPUT_FOLDER: Symbol(),
|
|
8
|
+
};
|
|
19
9
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
});
|
|
10
|
+
static preparePaths(apis, outputBase) {
|
|
11
|
+
this.output = `${process.cwd()}/${outputBase}`;
|
|
12
|
+
this.apis = apis;
|
|
39
13
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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));
|
|
110
|
-
});
|
|
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 });
|
|
14
|
+
static prepareModel(swg, indexSwg, isHttpsEnable) {
|
|
15
|
+
swg[this.SYMBOL.INDEX_SWG] = indexSwg;
|
|
16
|
+
swg.host =
|
|
17
|
+
swg.host &&
|
|
18
|
+
(isHttpsEnable ? 'https' : 'http') +
|
|
19
|
+
`://${swg.host.replace(/:[0-9]*/g, '')}`;
|
|
20
|
+
if (!swg.basePath) {
|
|
21
|
+
swg.basePath = '';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//#region @backend
|
|
25
|
+
static recreateIfNotExist(pathToFileOrFolder, content) {
|
|
26
|
+
if (___NS__isUndefined(content)) {
|
|
27
|
+
if (fse.existsSync(pathToFileOrFolder)) {
|
|
28
|
+
Helpers__NS__remove(pathToFileOrFolder);
|
|
131
29
|
}
|
|
132
|
-
|
|
30
|
+
fse.mkdirpSync(pathToFileOrFolder);
|
|
133
31
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
32
|
+
else {
|
|
33
|
+
if (fse.existsSync(pathToFileOrFolder)) {
|
|
34
|
+
fse.unlinkSync(pathToFileOrFolder);
|
|
35
|
+
}
|
|
36
|
+
const dirName = path.dirname(pathToFileOrFolder);
|
|
37
|
+
if (!fse.existsSync(dirName)) {
|
|
38
|
+
fse.mkdirpSync(dirName);
|
|
39
|
+
}
|
|
40
|
+
fse.writeFileSync(pathToFileOrFolder, content, {
|
|
41
|
+
encoding: 'utf8',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
static get serviceFromTag() {
|
|
47
|
+
const self = this;
|
|
48
|
+
return {
|
|
49
|
+
allClassNames() {
|
|
50
|
+
const names = [];
|
|
51
|
+
self.apis.map(swg => {
|
|
52
|
+
swg.tags.forEach(tag => {
|
|
53
|
+
// @ts-ignore
|
|
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 = ___NS__upperFirst(___NS__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
|
+
};
|
|
155
109
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
110
|
+
static get groupFromJSON() {
|
|
111
|
+
const self = this;
|
|
112
|
+
return {
|
|
113
|
+
get allGroupNames() {
|
|
114
|
+
const names = [];
|
|
115
|
+
self.apis.map(swg => {
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
names.push(self.groupFromJSON.folderName(swg));
|
|
118
|
+
});
|
|
119
|
+
return names;
|
|
120
|
+
},
|
|
121
|
+
folderName(swg) {
|
|
122
|
+
const basePath = swg.basePath;
|
|
123
|
+
const index = swg[self.SYMBOL.INDEX_SWG];
|
|
124
|
+
return ___NS__upperFirst(___NS__camelCase(basePath.trim() === '' ? `json${index}` : basePath));
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
static findTags(swg) {
|
|
129
|
+
const tags = [];
|
|
130
|
+
Object.keys(swg.paths).forEach(p => {
|
|
131
|
+
Object.keys(swg.paths[p]).forEach(m => {
|
|
132
|
+
const a = swg.paths[p][m];
|
|
133
|
+
if (___NS__isArray(a.tags)) {
|
|
134
|
+
a.tags.forEach(tag => {
|
|
135
|
+
if (tags.filter(({ name }) => name === tag).length === 0) {
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
tags.push({ name: tag });
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
return tags;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* To generate get/books/{id} => get_books__id_
|
|
147
|
+
*/
|
|
148
|
+
static cleanPath(path) {
|
|
149
|
+
return path
|
|
150
|
+
.replace(/{/g, '_')
|
|
151
|
+
.replace(/}/g, '_')
|
|
152
|
+
.replace(/\//g, '_')
|
|
153
|
+
.replace(/-/g, '_');
|
|
154
|
+
}
|
|
155
|
+
static cleanPathModel(pathModel) {
|
|
156
|
+
return pathModel.replace(/\/{/g, '/:').replace(/}/g, '');
|
|
157
|
+
}
|
|
158
|
+
static swaggerTypeToJS(type, itemsType = 'any') {
|
|
159
|
+
return type === 'integer'
|
|
160
|
+
? 'number'
|
|
161
|
+
: type === 'array'
|
|
162
|
+
? !itemsType
|
|
163
|
+
? 'any'
|
|
164
|
+
: `${this.swaggerTypeToJS(itemsType)}[]`
|
|
165
|
+
: type === 'file'
|
|
166
|
+
? 'any'
|
|
167
|
+
: type;
|
|
168
|
+
}
|
|
169
|
+
static getObjectDefinition(ref, swg, deep = 0) {
|
|
170
|
+
if (deep == 1)
|
|
171
|
+
return '';
|
|
172
|
+
if (!ref) {
|
|
173
|
+
console.log('Bad json $ref inside swagger');
|
|
174
|
+
return '';
|
|
199
175
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
176
|
+
let res = '';
|
|
177
|
+
ref = ref.replace('#/', '').replace(/\//g, '.');
|
|
178
|
+
let obj = (___NS__get(swg, ref));
|
|
179
|
+
// if (obj.properties.viaAgentViaGroupDTOs && !getObjectDefinition.prototype.once) {
|
|
180
|
+
// console.log('============================================================')
|
|
181
|
+
// console.log('obj', obj)
|
|
182
|
+
// console.log('------------------------------------------------------------')
|
|
183
|
+
// getObjectDefinition.prototype.once = true;
|
|
184
|
+
___NS__forOwn(obj.properties, (v, k) => {
|
|
185
|
+
// console.log(obj)
|
|
186
|
+
if (v.$ref && typeof v.$ref === 'string') {
|
|
187
|
+
res +=
|
|
188
|
+
k + ':{' + this.getObjectDefinition(v.$ref, swg, deep++) + '};\n';
|
|
189
|
+
}
|
|
190
|
+
else if (v.schema &&
|
|
191
|
+
v.schema.$ref &&
|
|
192
|
+
typeof v.schema.$ref === 'string') {
|
|
193
|
+
res +=
|
|
194
|
+
k +
|
|
195
|
+
':{' +
|
|
196
|
+
this.getObjectDefinition(v.schema.$ref, swg, deep++) +
|
|
197
|
+
'};\n';
|
|
198
|
+
}
|
|
199
|
+
else if (v.items &&
|
|
200
|
+
v.items.$ref &&
|
|
201
|
+
typeof v.items.$ref === 'string' &&
|
|
202
|
+
v.type &&
|
|
203
|
+
v.type === 'array') {
|
|
204
|
+
res +=
|
|
205
|
+
k +
|
|
206
|
+
':{' +
|
|
207
|
+
this.getObjectDefinition(v.items.$ref, swg, deep++) +
|
|
208
|
+
'}[];\n';
|
|
209
|
+
// console.log('make love here')
|
|
210
|
+
}
|
|
211
|
+
else if (v.items && v.items.$ref && typeof v.items.$ref === 'string') {
|
|
212
|
+
res +=
|
|
213
|
+
k +
|
|
214
|
+
':{' +
|
|
215
|
+
this.getObjectDefinition(v.items.$ref, swg, deep++) +
|
|
216
|
+
'};\n';
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
let isRequired = obj.required &&
|
|
220
|
+
obj.required instanceof Array &&
|
|
221
|
+
obj.required.filter(o => o === k).length > 0;
|
|
222
|
+
let type = v.enum && v.enum instanceof Array && v.enum.length > 0
|
|
223
|
+
? v.enum.map(e => '"' + e + '"').join('|')
|
|
224
|
+
: this.swaggerTypeToJS(v.type, v.items ? v.items.type : 'any');
|
|
225
|
+
res += k + (!isRequired ? '?' : '') + ':' + type + ';\n';
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
// console.log('res', res)
|
|
229
|
+
// }
|
|
230
|
+
return res;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* private pathes = {
|
|
234
|
+
* get_all_companies: new SimpleResource<
|
|
235
|
+
* string, A, TA, RP extends Object, QP extends Rest.UrlParams>(endpoint, model),
|
|
236
|
+
* get_byid_companies: new SimpleResource<
|
|
237
|
+
* string, A, TA, RP extends Object, QP extends Rest.UrlParams>(endpoint, model)
|
|
238
|
+
* }
|
|
239
|
+
*/
|
|
240
|
+
static getAngularPrivatePathesByTag(swg, tag) {
|
|
241
|
+
let res = [];
|
|
242
|
+
let base = swg.basePath.replace('/', '');
|
|
243
|
+
let pathes = {};
|
|
244
|
+
___NS__forOwn(swg.paths, (v, k) => {
|
|
245
|
+
___NS__forOwn(v, (v2, k2) => {
|
|
246
|
+
if (___NS__isArray(v2.tags) &&
|
|
247
|
+
v2.tags.filter(f => f === tag.name).length > 0) {
|
|
248
|
+
let resp = v2.responses['200'] && v2.responses['200'].schema;
|
|
249
|
+
// if (resp) {
|
|
250
|
+
// TODO response handling
|
|
251
|
+
// console.log('resp',resp);
|
|
252
|
+
if (pathes[k] === void 0)
|
|
253
|
+
pathes[k] = {}; // @ts-ignore
|
|
254
|
+
let type = this.getResponseType(resp, swg);
|
|
255
|
+
if (type.length > 3 &&
|
|
256
|
+
type.charAt(type.length - 1) === ']' &&
|
|
257
|
+
type.charAt(type.length - 2) === '[' &&
|
|
258
|
+
!pathes[k]['array']) {
|
|
259
|
+
pathes[k]['array'] = type;
|
|
260
|
+
}
|
|
261
|
+
else if (k2 !== 'delete' && !pathes[k]['single']) {
|
|
262
|
+
pathes[k]['single'] = type;
|
|
263
|
+
}
|
|
264
|
+
// }
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
let pathResources = [];
|
|
269
|
+
___NS__forOwn(pathes, (v, p) => {
|
|
270
|
+
// console.log(`${p} - ${JSON.stringify(v)}`);
|
|
271
|
+
pathResources.push({
|
|
272
|
+
clean_path: this.cleanPath(p),
|
|
273
|
+
model: this.cleanPathModel(p),
|
|
274
|
+
endpoint: swg.basePath,
|
|
275
|
+
singleModelType: !v['single'] ? 'any' : v['single'],
|
|
276
|
+
multipleModelType: !v['array'] ? 'any' : v['array'],
|
|
277
|
+
queryParamsType: 'any',
|
|
278
|
+
pathParamsType: 'any',
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
pathResources.forEach(p => {
|
|
282
|
+
res.push(`${p.clean_path}: new SimpleResource<\n${p.singleModelType},\n${p.multipleModelType}\n>( Ng2RestGenModule.enpointUrls.${this.groupFromJSON.folderName(swg)}, '${p.model}' )`);
|
|
283
|
+
});
|
|
284
|
+
return `private pathes = { \n${res.join(',\n')}\n};`;
|
|
285
|
+
}
|
|
286
|
+
/*
|
|
227
287
|
schema": {
|
|
228
288
|
"type": "array",
|
|
229
289
|
"items": {
|
|
@@ -235,153 +295,206 @@ ${res.join(",\n")}
|
|
|
235
295
|
"$ref": "#/definitions/CompanyDTO"
|
|
236
296
|
}
|
|
237
297
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
298
|
+
static getResponseType(o, swg) {
|
|
299
|
+
let res = '{} | any';
|
|
300
|
+
if (o && o.$ref && typeof o.$ref === 'string' && o.$ref.trim() !== '') {
|
|
301
|
+
res = '{' + this.getObjectDefinition(o.$ref, swg) + '}';
|
|
302
|
+
// console.log('I am object', o.$ref)
|
|
303
|
+
}
|
|
304
|
+
else if (o &&
|
|
305
|
+
o.type === 'array' &&
|
|
306
|
+
o.items &&
|
|
307
|
+
o.items.$ref &&
|
|
308
|
+
typeof o.items.$ref === 'string' &&
|
|
309
|
+
o.items.$ref.trim() !== '') {
|
|
310
|
+
res = '{' + this.getObjectDefinition(o.items.$ref, swg) + '}[]';
|
|
311
|
+
// console.log('I am array ', o.items.$ref)
|
|
312
|
+
}
|
|
313
|
+
// console.log('============================================================')
|
|
314
|
+
// console.log('type', res)
|
|
315
|
+
// console.log('------------------------------------------------------------')
|
|
316
|
+
return res;
|
|
244
317
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
318
|
+
//#region @backend
|
|
319
|
+
/**
|
|
320
|
+
* public getAllCompanies = ({ params },{ queryparams1 }) => this.pathes.get_all_companies.model(params).get(queryparams),
|
|
321
|
+
* public getAllCompanies = ({ params },{ queryparams1 },{body}) => this.pathes.get_all_companies.model(params).put(body,queryparams)
|
|
322
|
+
*/
|
|
323
|
+
static getServicesMethod(swg, tag) {
|
|
324
|
+
let methods = [];
|
|
325
|
+
for (let urlpath in swg.paths) {
|
|
326
|
+
for (let methodhttp in swg.paths[urlpath]) {
|
|
327
|
+
let m = swg.paths[urlpath][methodhttp];
|
|
328
|
+
if (___NS__isArray(m.tags) &&
|
|
329
|
+
m.tags.filter(t => t === tag.name).length === 1) {
|
|
330
|
+
let sm = {};
|
|
331
|
+
sm.summary = ___NS__camelCase(m.operationId ? m.operationId : m.summary);
|
|
332
|
+
sm.method = methodhttp; // <Models.Morphi.Rest.HttpMethod>methodhttp;
|
|
333
|
+
sm.path_cleand = this.cleanPath(urlpath);
|
|
334
|
+
// console.log('sm.path_cleand', sm.path_cleand)
|
|
335
|
+
sm.params = {};
|
|
336
|
+
sm.params.query = [];
|
|
337
|
+
sm.params.path = [];
|
|
338
|
+
sm.params.body = [];
|
|
339
|
+
sm.comment = '';
|
|
340
|
+
// QUICKFIX
|
|
341
|
+
if (m.responses &&
|
|
342
|
+
m.responses['200'] &&
|
|
343
|
+
m.responses['200'].schema && // @ts-ignore
|
|
344
|
+
m.responses['200'].schema.type && // @ts-ignore
|
|
345
|
+
m.responses['200'].schema.type === 'array') {
|
|
346
|
+
sm.isArray = true;
|
|
347
|
+
}
|
|
348
|
+
if (m.parameters)
|
|
349
|
+
m.parameters.forEach(param => {
|
|
350
|
+
let ptypeExitst = param.type && param.type.length > 0;
|
|
351
|
+
sm.comment +=
|
|
352
|
+
'*' +
|
|
353
|
+
(ptypeExitst ? ` { ${param.type} } ` : ' ') +
|
|
354
|
+
`${param.name} (${param.description})` +
|
|
355
|
+
'\n';
|
|
356
|
+
if (param.in === 'body') {
|
|
357
|
+
let type;
|
|
358
|
+
if (param.schema.items &&
|
|
359
|
+
param.schema.items.$ref &&
|
|
360
|
+
param.schema.type == 'array') {
|
|
361
|
+
type =
|
|
362
|
+
'{' +
|
|
363
|
+
this.getObjectDefinition(param.schema.items.$ref, swg) +
|
|
364
|
+
'}[]';
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
type = param.schema.$ref
|
|
368
|
+
? '{' +
|
|
369
|
+
this.getObjectDefinition(param.schema.$ref, swg) +
|
|
370
|
+
'}'
|
|
371
|
+
: this.swaggerTypeToJS(param.type);
|
|
372
|
+
}
|
|
373
|
+
// @ts-ignore
|
|
374
|
+
sm.params.body.push({
|
|
375
|
+
name: param.name,
|
|
376
|
+
type,
|
|
377
|
+
required: param.required,
|
|
378
|
+
isObject: true,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
if (!___NS__isArray(sm.params[param.in])) {
|
|
383
|
+
sm.params[param.in] = [];
|
|
384
|
+
}
|
|
385
|
+
sm.params[param.in].push({
|
|
386
|
+
name: param.name,
|
|
387
|
+
type: this.swaggerTypeToJS(param.type),
|
|
388
|
+
required: param.required,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
methods.push(sm);
|
|
293
393
|
}
|
|
294
|
-
|
|
295
|
-
name: param.name,
|
|
296
|
-
type: this.swaggerTypeToJS(param.type),
|
|
297
|
-
required: param.required
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
methods.push(sm);
|
|
394
|
+
}
|
|
302
395
|
}
|
|
303
|
-
|
|
396
|
+
return methods;
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region @backend
|
|
400
|
+
static getAngularServicesMethods(swg, tag) {
|
|
401
|
+
let res = '';
|
|
402
|
+
let methods = this.getServicesMethod(swg, tag);
|
|
403
|
+
methods.forEach(m => {
|
|
404
|
+
let neededParams = {
|
|
405
|
+
path: m.params && m.params.path && m.params.path.length > 0,
|
|
406
|
+
query: m.params && m.params.query && m.params.query.length > 0,
|
|
407
|
+
body: m.params && m.params.body && m.params.body.length > 0,
|
|
408
|
+
};
|
|
409
|
+
let paramsPath = neededParams.path // @ts-ignore
|
|
410
|
+
? m.params.path
|
|
411
|
+
.map(p => (p['joined'] = p.name + ':' + p.type))
|
|
412
|
+
.join(',')
|
|
413
|
+
: '';
|
|
414
|
+
let paramsQuery = neededParams.query // @ts-ignore
|
|
415
|
+
? m.params.query
|
|
416
|
+
.map(p => (p['joined'] = p.name + ':' + p.type))
|
|
417
|
+
.join(',')
|
|
418
|
+
: '';
|
|
419
|
+
let paramsBody = neededParams.body // @ts-ignore
|
|
420
|
+
? m.params.body
|
|
421
|
+
.map(p => (p['joined'] = p.name + ':' + p.type))
|
|
422
|
+
.join(',')
|
|
423
|
+
: '';
|
|
424
|
+
let paramPathNames = '{' +
|
|
425
|
+
(neededParams.path // @ts-ignore
|
|
426
|
+
? m.params.path
|
|
427
|
+
.map(p => (p['joined'] = p.name))
|
|
428
|
+
.filter(d => d)
|
|
429
|
+
.join(',')
|
|
430
|
+
: '') +
|
|
431
|
+
'}';
|
|
432
|
+
let paramQueryNames = '{' +
|
|
433
|
+
(neededParams.query // @ts-ignore
|
|
434
|
+
? m.params.query
|
|
435
|
+
.map(p => (p['joined'] = p.name))
|
|
436
|
+
.filter(d => d)
|
|
437
|
+
.join(',')
|
|
438
|
+
: '') +
|
|
439
|
+
'}';
|
|
440
|
+
let paramBodyNames = '{' +
|
|
441
|
+
(neededParams.body // @ts-ignore
|
|
442
|
+
? m.params.body
|
|
443
|
+
.map(p => (p['joined'] = p.name))
|
|
444
|
+
.filter(d => d)
|
|
445
|
+
.join(',')
|
|
446
|
+
: '') +
|
|
447
|
+
'}';
|
|
448
|
+
let method = m.method;
|
|
449
|
+
if (m.isArray && m.method === 'get')
|
|
450
|
+
method = 'query';
|
|
451
|
+
let params = [paramsPath, paramsQuery, paramsBody]
|
|
452
|
+
.filter(d => d && d !== '{}')
|
|
453
|
+
.join(',');
|
|
454
|
+
// QUICKFIX change {object} to object in method
|
|
455
|
+
// @ts-ignore
|
|
456
|
+
if (neededParams.query &&
|
|
457
|
+
m.params.query.length === 1 &&
|
|
458
|
+
m.params.query[0].isObject) {
|
|
459
|
+
// @ts-ignore
|
|
460
|
+
paramQueryNames = paramQueryNames.match(new RegExp('[a-zA-Z]+', 'g'))[0];
|
|
461
|
+
}
|
|
462
|
+
// @ts-ignore
|
|
463
|
+
if (neededParams.body &&
|
|
464
|
+
m.params.body.length === 1 &&
|
|
465
|
+
m.params.body[0].isObject) {
|
|
466
|
+
// @ts-ignore
|
|
467
|
+
paramBodyNames = paramBodyNames.match(new RegExp('[a-zA-Z]+', 'g'))[0];
|
|
468
|
+
}
|
|
469
|
+
let paramsName = [paramBodyNames, paramQueryNames]
|
|
470
|
+
.filter(d => d && d !== '{}')
|
|
471
|
+
.map(d => '<any>' + d)
|
|
472
|
+
.join(',');
|
|
473
|
+
let comment = m.comment
|
|
474
|
+
? `/**` +
|
|
475
|
+
'\n' +
|
|
476
|
+
`${m.comment.trim()}
|
|
477
|
+
*/`
|
|
478
|
+
: '';
|
|
479
|
+
res +=
|
|
480
|
+
`${comment}
|
|
481
|
+
public` +
|
|
482
|
+
this.recreateSummary(m.summary) +
|
|
483
|
+
'= (' +
|
|
484
|
+
params +
|
|
485
|
+
') =>\nthis.pathes.' +
|
|
486
|
+
m.path_cleand +
|
|
487
|
+
`\n.model(${paramPathNames}) \n.${method} (${paramsName}); ` +
|
|
488
|
+
'\n';
|
|
489
|
+
});
|
|
490
|
+
return res;
|
|
491
|
+
}
|
|
492
|
+
//#endregion
|
|
493
|
+
static { this.count1 = 0; }
|
|
494
|
+
static recreateSummary(summary) {
|
|
495
|
+
// if (!summary) {
|
|
496
|
+
// return 'SummaryExample' + (count1++)
|
|
497
|
+
// }
|
|
498
|
+
return summary;
|
|
304
499
|
}
|
|
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
|
-
// }
|
|
384
500
|
}
|
|
385
|
-
export {
|
|
386
|
-
HelpersSwagger
|
|
387
|
-
};
|