@tsed/swagger 6.88.1 → 6.92.0
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/{SwaggerModule.d.ts → cjs/SwaggerModule.d.ts} +2 -0
- package/lib/cjs/SwaggerModule.js +129 -0
- package/lib/cjs/SwaggerModule.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/docs.d.ts +0 -0
- package/lib/cjs/decorators/docs.js +18 -0
- package/lib/cjs/decorators/docs.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/hidden.d.ts +0 -0
- package/lib/cjs/decorators/hidden.js +40 -0
- package/lib/cjs/decorators/hidden.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +9 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/SwaggerSettings.d.ts +0 -0
- package/lib/cjs/interfaces/SwaggerSettings.js +3 -0
- package/lib/cjs/interfaces/SwaggerSettings.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/index.d.ts +0 -0
- package/lib/cjs/interfaces/index.js +5 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/cssMiddleware.d.ts +0 -0
- package/lib/cjs/middlewares/cssMiddleware.js +23 -0
- package/lib/cjs/middlewares/cssMiddleware.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/indexMiddleware.d.ts +0 -0
- package/lib/cjs/middlewares/indexMiddleware.js +24 -0
- package/lib/cjs/middlewares/indexMiddleware.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/jsMiddleware.d.ts +0 -0
- package/lib/cjs/middlewares/jsMiddleware.js +18 -0
- package/lib/cjs/middlewares/jsMiddleware.js.map +1 -0
- package/lib/{middlewares → cjs/middlewares}/redirectMiddleware.d.ts +0 -0
- package/lib/cjs/middlewares/redirectMiddleware.js +16 -0
- package/lib/cjs/middlewares/redirectMiddleware.js.map +1 -0
- package/lib/{services → cjs/services}/SwaggerService.d.ts +0 -0
- package/lib/cjs/services/SwaggerService.js +103 -0
- package/lib/cjs/services/SwaggerService.js.map +1 -0
- package/lib/{utils → cjs/utils}/getSpecType.d.ts +0 -0
- package/lib/cjs/utils/getSpecType.js +21 -0
- package/lib/cjs/utils/getSpecType.js.map +1 -0
- package/lib/{utils → cjs/utils}/includeRoute.d.ts +0 -0
- package/lib/cjs/utils/includeRoute.js +20 -0
- package/lib/cjs/utils/includeRoute.js.map +1 -0
- package/lib/{utils → cjs/utils}/index.d.ts +0 -0
- package/lib/cjs/utils/index.js +11 -0
- package/lib/cjs/utils/index.js.map +1 -0
- package/lib/{utils → cjs/utils}/mapOpenSpec.d.ts +0 -0
- package/lib/cjs/utils/mapOpenSpec.js +40 -0
- package/lib/cjs/utils/mapOpenSpec.js.map +1 -0
- package/lib/{utils → cjs/utils}/mapOpenSpec2.d.ts +0 -0
- package/lib/cjs/utils/mapOpenSpec2.js +34 -0
- package/lib/cjs/utils/mapOpenSpec2.js.map +1 -0
- package/lib/{utils → cjs/utils}/mapOpenSpec3.d.ts +0 -0
- package/lib/cjs/utils/mapOpenSpec3.js +26 -0
- package/lib/cjs/utils/mapOpenSpec3.js.map +1 -0
- package/lib/{utils → cjs/utils}/mapOpenSpecInfo.d.ts +0 -0
- package/lib/cjs/utils/mapOpenSpecInfo.js +21 -0
- package/lib/cjs/utils/mapOpenSpecInfo.js.map +1 -0
- package/lib/{utils → cjs/utils}/matchPath.d.ts +0 -0
- package/lib/cjs/utils/matchPath.js +10 -0
- package/lib/cjs/utils/matchPath.js.map +1 -0
- package/lib/esm/SwaggerModule.js +126 -0
- package/lib/esm/SwaggerModule.js.map +1 -0
- package/lib/esm/decorators/docs.js +14 -0
- package/lib/esm/decorators/docs.js.map +1 -0
- package/lib/esm/decorators/hidden.js +36 -0
- package/lib/esm/decorators/hidden.js.map +1 -0
- package/lib/esm/index.js +6 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/SwaggerSettings.js +2 -0
- package/lib/esm/interfaces/SwaggerSettings.js.map +1 -0
- package/lib/esm/interfaces/index.js +2 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/middlewares/cssMiddleware.js +18 -0
- package/lib/esm/middlewares/cssMiddleware.js.map +1 -0
- package/lib/esm/middlewares/indexMiddleware.js +20 -0
- package/lib/esm/middlewares/indexMiddleware.js.map +1 -0
- package/lib/esm/middlewares/jsMiddleware.js +13 -0
- package/lib/esm/middlewares/jsMiddleware.js.map +1 -0
- package/lib/esm/middlewares/redirectMiddleware.js +12 -0
- package/lib/esm/middlewares/redirectMiddleware.js.map +1 -0
- package/lib/esm/services/SwaggerService.js +100 -0
- package/lib/esm/services/SwaggerService.js.map +1 -0
- package/lib/esm/utils/getSpecType.js +16 -0
- package/lib/esm/utils/getSpecType.js.map +1 -0
- package/lib/esm/utils/includeRoute.js +16 -0
- package/lib/esm/utils/includeRoute.js.map +1 -0
- package/lib/esm/utils/index.js +8 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/esm/utils/mapOpenSpec.js +36 -0
- package/lib/esm/utils/mapOpenSpec.js.map +1 -0
- package/lib/esm/utils/mapOpenSpec2.js +30 -0
- package/lib/esm/utils/mapOpenSpec2.js.map +1 -0
- package/lib/esm/utils/mapOpenSpec3.js +22 -0
- package/lib/esm/utils/mapOpenSpec3.js.map +1 -0
- package/lib/esm/utils/mapOpenSpecInfo.js +17 -0
- package/lib/esm/utils/mapOpenSpecInfo.js.map +1 -0
- package/lib/esm/utils/matchPath.js +5 -0
- package/lib/esm/utils/matchPath.js.map +1 -0
- package/lib/types/SwaggerModule.d.ts +30 -0
- package/lib/types/decorators/docs.d.ts +10 -0
- package/lib/types/decorators/hidden.d.ts +32 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/interfaces/SwaggerSettings.d.ts +99 -0
- package/lib/types/interfaces/index.d.ts +9 -0
- package/lib/types/middlewares/cssMiddleware.d.ts +6 -0
- package/lib/types/middlewares/indexMiddleware.d.ts +10 -0
- package/lib/types/middlewares/jsMiddleware.d.ts +6 -0
- package/lib/types/middlewares/redirectMiddleware.d.ts +6 -0
- package/lib/types/services/SwaggerService.d.ts +29 -0
- package/lib/types/utils/getSpecType.d.ts +12 -0
- package/lib/types/utils/includeRoute.d.ts +3 -0
- package/lib/types/utils/index.d.ts +7 -0
- package/lib/types/utils/mapOpenSpec.d.ts +10 -0
- package/lib/types/utils/mapOpenSpec2.d.ts +9 -0
- package/lib/types/utils/mapOpenSpec3.d.ts +8 -0
- package/lib/types/utils/mapOpenSpecInfo.d.ts +6 -0
- package/lib/types/utils/matchPath.d.ts +1 -0
- package/lib/views/index.ejs +145 -0
- package/lib/views/index.html +144 -0
- package/package.json +22 -18
- package/tsconfig.compile.esm.json +24 -0
- package/lib/index.js +0 -623
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -617
- package/lib/index.modern.js.map +0 -1
package/lib/index.js
DELETED
|
@@ -1,623 +0,0 @@
|
|
|
1
|
-
var tslib = require('tslib');
|
|
2
|
-
var common = require('@tsed/common');
|
|
3
|
-
var core = require('@tsed/core');
|
|
4
|
-
var schema = require('@tsed/schema');
|
|
5
|
-
var Fs = require('fs');
|
|
6
|
-
var micromatch = require('micromatch');
|
|
7
|
-
var path = require('path');
|
|
8
|
-
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var Fs__default = /*#__PURE__*/_interopDefaultLegacy(Fs);
|
|
12
|
-
var micromatch__default = /*#__PURE__*/_interopDefaultLegacy(micromatch);
|
|
13
|
-
|
|
14
|
-
function _extends() {
|
|
15
|
-
_extends = Object.assign || function (target) {
|
|
16
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
17
|
-
var source = arguments[i];
|
|
18
|
-
|
|
19
|
-
for (var key in source) {
|
|
20
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
21
|
-
target[key] = source[key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return target;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return _extends.apply(this, arguments);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var id = 0;
|
|
33
|
-
|
|
34
|
-
function _classPrivateFieldLooseKey(name) {
|
|
35
|
-
return "__private_" + id++ + "_" + name;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _classPrivateFieldLooseBase(receiver, privateKey) {
|
|
39
|
-
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
|
|
40
|
-
throw new TypeError("attempted to use private field on non-instance");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return receiver;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @ignore
|
|
48
|
-
* @param version
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
function getSpecType(version) {
|
|
52
|
-
return version.startsWith("3.") ? schema.SpecTypes.OPENAPI : schema.SpecTypes.SWAGGER;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @ignore
|
|
56
|
-
* @param spec
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
function getSpecTypeFromSpec(spec) {
|
|
60
|
-
return "openapi" in spec ? schema.SpecTypes.OPENAPI : schema.SpecTypes.SWAGGER;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @ignore
|
|
65
|
-
* @param info
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
function mapOpenSpecInfo(info) {
|
|
69
|
-
const {
|
|
70
|
-
title,
|
|
71
|
-
description,
|
|
72
|
-
version,
|
|
73
|
-
termsOfService,
|
|
74
|
-
contact,
|
|
75
|
-
license
|
|
76
|
-
} = info;
|
|
77
|
-
return core.cleanObject({
|
|
78
|
-
version,
|
|
79
|
-
title,
|
|
80
|
-
description,
|
|
81
|
-
termsOfService,
|
|
82
|
-
contact,
|
|
83
|
-
license
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @ignore
|
|
89
|
-
* @param spec
|
|
90
|
-
* @param version
|
|
91
|
-
* @param specVersion
|
|
92
|
-
* @param acceptMimes
|
|
93
|
-
*/
|
|
94
|
-
|
|
95
|
-
function mapOpenSpec2(spec, {
|
|
96
|
-
version,
|
|
97
|
-
specVersion,
|
|
98
|
-
acceptMimes = ["application/json"]
|
|
99
|
-
}) {
|
|
100
|
-
const {
|
|
101
|
-
paths,
|
|
102
|
-
security,
|
|
103
|
-
tags,
|
|
104
|
-
host,
|
|
105
|
-
basePath,
|
|
106
|
-
schemes,
|
|
107
|
-
consumes = [],
|
|
108
|
-
produces = ["application/json"],
|
|
109
|
-
definitions,
|
|
110
|
-
parameters,
|
|
111
|
-
responses,
|
|
112
|
-
securityDefinitions,
|
|
113
|
-
externalDocs
|
|
114
|
-
} = spec;
|
|
115
|
-
return {
|
|
116
|
-
swagger: specVersion,
|
|
117
|
-
consumes: core.uniq([...acceptMimes, ...consumes]),
|
|
118
|
-
produces: core.uniq([...produces]),
|
|
119
|
-
info: mapOpenSpecInfo(core.getValue(spec, "info", {})),
|
|
120
|
-
paths,
|
|
121
|
-
host,
|
|
122
|
-
basePath,
|
|
123
|
-
schemes,
|
|
124
|
-
definitions,
|
|
125
|
-
parameters,
|
|
126
|
-
responses,
|
|
127
|
-
security,
|
|
128
|
-
securityDefinitions,
|
|
129
|
-
tags,
|
|
130
|
-
externalDocs
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @ignore
|
|
136
|
-
* @param spec
|
|
137
|
-
* @param version
|
|
138
|
-
* @param specVersion
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
function mapOpenSpec3(spec, {
|
|
142
|
-
specVersion
|
|
143
|
-
}) {
|
|
144
|
-
const {
|
|
145
|
-
servers,
|
|
146
|
-
paths,
|
|
147
|
-
components,
|
|
148
|
-
security,
|
|
149
|
-
tags,
|
|
150
|
-
externalDocs
|
|
151
|
-
} = spec;
|
|
152
|
-
return {
|
|
153
|
-
openapi: specVersion,
|
|
154
|
-
info: mapOpenSpecInfo(core.getValue(spec, "info", {})),
|
|
155
|
-
servers,
|
|
156
|
-
paths,
|
|
157
|
-
components,
|
|
158
|
-
security,
|
|
159
|
-
tags,
|
|
160
|
-
externalDocs
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* @ignore
|
|
166
|
-
* @param spec
|
|
167
|
-
* @param fileSpec
|
|
168
|
-
* @param version
|
|
169
|
-
* @param acceptMimes
|
|
170
|
-
* @param specVersion
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
function mapOpenSpec(spec, {
|
|
174
|
-
fileSpec,
|
|
175
|
-
acceptMimes,
|
|
176
|
-
specVersion,
|
|
177
|
-
version
|
|
178
|
-
}) {
|
|
179
|
-
specVersion = specVersion || core.getValue(spec, "openapi", core.getValue(spec, "swagger", "2.0"));
|
|
180
|
-
const options = {
|
|
181
|
-
specVersion,
|
|
182
|
-
acceptMimes
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
switch (getSpecType(specVersion)) {
|
|
186
|
-
case schema.SpecTypes.OPENAPI:
|
|
187
|
-
spec = mapOpenSpec3(spec, options);
|
|
188
|
-
fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;
|
|
189
|
-
break;
|
|
190
|
-
|
|
191
|
-
default:
|
|
192
|
-
case schema.SpecTypes.SWAGGER:
|
|
193
|
-
spec = mapOpenSpec2(spec, options);
|
|
194
|
-
fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
spec = schema.mergeSpec(spec, fileSpec);
|
|
199
|
-
core.setValue(spec, "info.title", core.getValue(spec, "info.title", "Api documentation"));
|
|
200
|
-
core.setValue(spec, "info.version", core.getValue(spec, "info.version", version));
|
|
201
|
-
return spec;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function matchPath(path, patterns) {
|
|
205
|
-
return patterns && patterns.length ? micromatch__default['default'].isMatch(path, patterns) : true;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function includeRoute(route, provider, conf) {
|
|
209
|
-
const hidden = provider.store.get("hidden");
|
|
210
|
-
const docs = provider.store.get("docs") || [];
|
|
211
|
-
const {
|
|
212
|
-
doc,
|
|
213
|
-
pathPatterns
|
|
214
|
-
} = conf;
|
|
215
|
-
const inDoc = doc && docs.indexOf(doc) > -1;
|
|
216
|
-
const pathPatternMatch = pathPatterns && matchPath(route, pathPatterns);
|
|
217
|
-
|
|
218
|
-
if (hidden) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (!doc && !pathPatterns) {
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return !!(inDoc || pathPatternMatch);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
var _specs;
|
|
230
|
-
exports.SwaggerService = (_specs = /*#__PURE__*/_classPrivateFieldLooseKey("specs"), class SwaggerService {
|
|
231
|
-
constructor(injectorService, platform, configuration) {
|
|
232
|
-
Object.defineProperty(this, _specs, {
|
|
233
|
-
writable: true,
|
|
234
|
-
value: void 0
|
|
235
|
-
});
|
|
236
|
-
this.injectorService = injectorService;
|
|
237
|
-
this.platform = platform;
|
|
238
|
-
this.configuration = configuration;
|
|
239
|
-
_classPrivateFieldLooseBase(this, _specs)[_specs] = new Map();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
getOpenAPISpec(conf) {
|
|
243
|
-
if (!_classPrivateFieldLooseBase(this, _specs)[_specs].has(conf.path)) {
|
|
244
|
-
const defaultSpec = this.getDefaultSpec(conf);
|
|
245
|
-
const specType = getSpecTypeFromSpec(defaultSpec);
|
|
246
|
-
let finalSpec = {};
|
|
247
|
-
const options = {
|
|
248
|
-
paths: {},
|
|
249
|
-
tags: [],
|
|
250
|
-
schemas: {},
|
|
251
|
-
specType,
|
|
252
|
-
operationIdFormatter: conf.operationIdFormatter,
|
|
253
|
-
operationIdPattern: conf.operationIdPattern,
|
|
254
|
-
|
|
255
|
-
append(spec) {
|
|
256
|
-
finalSpec = schema.mergeSpec(finalSpec, spec);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
};
|
|
260
|
-
this.platform.getMountedControllers().forEach(({
|
|
261
|
-
route,
|
|
262
|
-
provider
|
|
263
|
-
}) => {
|
|
264
|
-
if (includeRoute(route, provider, conf)) {
|
|
265
|
-
const spec = this.buildRoutes(provider, _extends({}, options, {
|
|
266
|
-
rootPath: route.replace(provider.path, "")
|
|
267
|
-
}));
|
|
268
|
-
options.append(spec);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
_classPrivateFieldLooseBase(this, _specs)[_specs].set(conf.path, schema.mergeSpec(defaultSpec, finalSpec));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return _classPrivateFieldLooseBase(this, _specs)[_specs].get(conf.path);
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Return the global api information.
|
|
279
|
-
*/
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
getDefaultSpec(conf) {
|
|
283
|
-
const {
|
|
284
|
-
version = "1.0.0",
|
|
285
|
-
acceptMimes
|
|
286
|
-
} = this.configuration;
|
|
287
|
-
const {
|
|
288
|
-
specPath,
|
|
289
|
-
specVersion
|
|
290
|
-
} = conf;
|
|
291
|
-
const fileSpec = specPath ? this.readSpecPath(specPath) : {};
|
|
292
|
-
return mapOpenSpec(core.getValue(conf, "spec", {}), {
|
|
293
|
-
fileSpec,
|
|
294
|
-
version,
|
|
295
|
-
specVersion,
|
|
296
|
-
acceptMimes
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
readSpecPath(path) {
|
|
301
|
-
path = this.configuration.resolve(path);
|
|
302
|
-
|
|
303
|
-
if (Fs__default['default'].existsSync(path)) {
|
|
304
|
-
const json = Fs__default['default'].readFileSync(path, {
|
|
305
|
-
encoding: "utf8"
|
|
306
|
-
});
|
|
307
|
-
/* istanbul ignore else */
|
|
308
|
-
|
|
309
|
-
if (json !== "") {
|
|
310
|
-
return JSON.parse(json);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return {};
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
*
|
|
318
|
-
* @param ctrl
|
|
319
|
-
* @param options
|
|
320
|
-
*/
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
buildRoutes(ctrl, options) {
|
|
324
|
-
const rootPath = options.rootPath + ctrl.path;
|
|
325
|
-
ctrl.children.map(ctrl => this.injectorService.getProvider(ctrl)).forEach(provider => {
|
|
326
|
-
if (!provider.store.get("hidden")) {
|
|
327
|
-
const spec = this.buildRoutes(provider, _extends({}, options, {
|
|
328
|
-
rootPath
|
|
329
|
-
}));
|
|
330
|
-
options.append(spec);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
return schema.getSpec(ctrl.token, options);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
});
|
|
337
|
-
exports.SwaggerService = tslib.__decorate([common.Injectable(), tslib.__param(2, common.Configuration()), tslib.__metadata("design:paramtypes", [common.InjectorService, common.Platform, Object])], exports.SwaggerService);
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* @ignore
|
|
341
|
-
* @param path
|
|
342
|
-
*/
|
|
343
|
-
|
|
344
|
-
function cssMiddleware(path$1) {
|
|
345
|
-
return ctx => {
|
|
346
|
-
const content = Fs__default['default'].readFileSync(path.resolve(path$1), {
|
|
347
|
-
encoding: "utf8"
|
|
348
|
-
});
|
|
349
|
-
ctx.response.setHeaders({
|
|
350
|
-
"Content-Type": "text/css"
|
|
351
|
-
}).status(200).body(content);
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* @ignore
|
|
357
|
-
* @param viewPath
|
|
358
|
-
* @param conf
|
|
359
|
-
*/
|
|
360
|
-
function indexMiddleware(viewPath, conf) {
|
|
361
|
-
return async ctx => {
|
|
362
|
-
const {
|
|
363
|
-
path = "/",
|
|
364
|
-
options = {},
|
|
365
|
-
showExplorer,
|
|
366
|
-
cssPath,
|
|
367
|
-
jsPath,
|
|
368
|
-
urls
|
|
369
|
-
} = conf;
|
|
370
|
-
ctx.response.body(await ctx.response.render(viewPath, {
|
|
371
|
-
spec: {},
|
|
372
|
-
url: `${path}/swagger.json`,
|
|
373
|
-
urls,
|
|
374
|
-
showExplorer,
|
|
375
|
-
cssPath,
|
|
376
|
-
jsPath,
|
|
377
|
-
swaggerOptions: options
|
|
378
|
-
}));
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* @ignore
|
|
384
|
-
* @param path
|
|
385
|
-
*/
|
|
386
|
-
|
|
387
|
-
function jsMiddleware(path$1) {
|
|
388
|
-
return ctx => {
|
|
389
|
-
const content = Fs__default['default'].readFileSync(path.resolve(path$1), {
|
|
390
|
-
encoding: "utf8"
|
|
391
|
-
});
|
|
392
|
-
ctx.response.setHeaders({
|
|
393
|
-
"Content-Type": "application/javascript"
|
|
394
|
-
}).status(200).body(content);
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* @ignore
|
|
400
|
-
* @param path
|
|
401
|
-
*/
|
|
402
|
-
function redirectMiddleware(path) {
|
|
403
|
-
return ctx => {
|
|
404
|
-
if (ctx.request.url === path && !ctx.request.url.match(/\/$/)) {
|
|
405
|
-
ctx.response.redirect(302, `${path}/`);
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const swaggerUiPath = require("swagger-ui-dist").absolutePath();
|
|
411
|
-
/**
|
|
412
|
-
* @ignore
|
|
413
|
-
*/
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
exports.SwaggerModule = class SwaggerModule {
|
|
417
|
-
constructor() {
|
|
418
|
-
this.loaded = false;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
get settings() {
|
|
422
|
-
return [].concat(this.configuration.get("swagger")).filter(o => !!o);
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
*
|
|
426
|
-
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
$beforeRoutesInit() {
|
|
430
|
-
if (this.loaded) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const urls = this.getUrls();
|
|
435
|
-
this.settings.forEach(conf => {
|
|
436
|
-
const {
|
|
437
|
-
path = "/"
|
|
438
|
-
} = conf;
|
|
439
|
-
this.app.get(path, common.useCtxHandler(redirectMiddleware(path)));
|
|
440
|
-
this.app.use(path, this.createRouter(conf, urls));
|
|
441
|
-
});
|
|
442
|
-
this.loaded = true;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
$onReady() {
|
|
446
|
-
// istanbul ignore next
|
|
447
|
-
if (this.configuration.getBestHost) {
|
|
448
|
-
const host = this.configuration.getBestHost();
|
|
449
|
-
|
|
450
|
-
if (!host) {
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const displayLog = conf => {
|
|
455
|
-
const {
|
|
456
|
-
path = "/",
|
|
457
|
-
fileName = "swagger.json",
|
|
458
|
-
doc
|
|
459
|
-
} = conf;
|
|
460
|
-
let url = "/";
|
|
461
|
-
|
|
462
|
-
if (host) {
|
|
463
|
-
url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
this.injector.logger.info(`[${doc || "default"}] Swagger JSON is available on ${url}${common.normalizePath(path, fileName)}`);
|
|
467
|
-
this.injector.logger.info(`[${doc || "default"}] Swagger UI is available on ${url}${path}/`);
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
this.settings.forEach(conf => {
|
|
471
|
-
displayLog(conf);
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
this.generateSpecFiles();
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
generateSpecFiles() {
|
|
479
|
-
return Promise.all(this.settings.map(conf => {
|
|
480
|
-
const {
|
|
481
|
-
outFile
|
|
482
|
-
} = conf;
|
|
483
|
-
|
|
484
|
-
if (outFile) {
|
|
485
|
-
const spec = this.swaggerService.getOpenAPISpec(conf);
|
|
486
|
-
return Fs__default['default'].writeFile(outFile, JSON.stringify(spec, null, 2), {
|
|
487
|
-
encoding: "utf8"
|
|
488
|
-
}, () => {});
|
|
489
|
-
}
|
|
490
|
-
}));
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
getUrls() {
|
|
494
|
-
return this.settings.reduce((acc, conf) => {
|
|
495
|
-
const {
|
|
496
|
-
path = "/",
|
|
497
|
-
fileName = "swagger.json",
|
|
498
|
-
doc,
|
|
499
|
-
hidden
|
|
500
|
-
} = conf;
|
|
501
|
-
|
|
502
|
-
if (!hidden) {
|
|
503
|
-
acc.push({
|
|
504
|
-
url: common.normalizePath(path, fileName),
|
|
505
|
-
name: doc || path
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
return acc;
|
|
510
|
-
}, []);
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
*
|
|
514
|
-
* @param conf
|
|
515
|
-
* @param urls
|
|
516
|
-
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
createRouter(conf, urls) {
|
|
520
|
-
const {
|
|
521
|
-
disableSpec = false,
|
|
522
|
-
fileName = "swagger.json",
|
|
523
|
-
cssPath,
|
|
524
|
-
jsPath,
|
|
525
|
-
viewPath = path.join(__dirname, "../views/index.ejs")
|
|
526
|
-
} = conf;
|
|
527
|
-
const router = common.PlatformRouter.create(this.injector);
|
|
528
|
-
|
|
529
|
-
if (!disableSpec) {
|
|
530
|
-
router.get(common.normalizePath("/", fileName), common.useCtxHandler(this.middlewareSwaggerJson(conf)));
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
if (viewPath) {
|
|
534
|
-
if (cssPath) {
|
|
535
|
-
router.get("/main.css", common.useCtxHandler(cssMiddleware(cssPath)));
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
if (jsPath) {
|
|
539
|
-
router.get("/main.js", common.useCtxHandler(jsMiddleware(jsPath)));
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
router.get("/", common.useCtxHandler(indexMiddleware(viewPath, _extends({
|
|
543
|
-
urls
|
|
544
|
-
}, conf))));
|
|
545
|
-
router.statics("/", {
|
|
546
|
-
root: swaggerUiPath
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
return router;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
middlewareSwaggerJson(conf) {
|
|
554
|
-
return ctx => {
|
|
555
|
-
ctx.response.status(200).body(this.swaggerService.getOpenAPISpec(conf));
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
tslib.__decorate([common.Inject(), tslib.__metadata("design:type", common.InjectorService)], exports.SwaggerModule.prototype, "injector", void 0);
|
|
562
|
-
|
|
563
|
-
tslib.__decorate([common.Inject(), tslib.__metadata("design:type", common.PlatformApplication)], exports.SwaggerModule.prototype, "app", void 0);
|
|
564
|
-
|
|
565
|
-
tslib.__decorate([common.Configuration(), tslib.__metadata("design:type", Object)], exports.SwaggerModule.prototype, "configuration", void 0);
|
|
566
|
-
|
|
567
|
-
tslib.__decorate([common.Inject(), tslib.__metadata("design:type", exports.SwaggerService)], exports.SwaggerModule.prototype, "swaggerService", void 0);
|
|
568
|
-
|
|
569
|
-
exports.SwaggerModule = tslib.__decorate([common.Module()], exports.SwaggerModule);
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Set the type documentation for this class.
|
|
573
|
-
*
|
|
574
|
-
* See [swagger documentation](/tutorials/swagger.html)
|
|
575
|
-
*
|
|
576
|
-
* @decorator
|
|
577
|
-
* @swagger
|
|
578
|
-
* @param docs
|
|
579
|
-
*/
|
|
580
|
-
|
|
581
|
-
function Docs(...docs) {
|
|
582
|
-
return core.StoreMerge("docs", docs);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* Disable documentation for the class and his endpoint.
|
|
587
|
-
*
|
|
588
|
-
* ````typescript
|
|
589
|
-
* @Controller('/')
|
|
590
|
-
* export class Ctrl {
|
|
591
|
-
*
|
|
592
|
-
* @Get('/')
|
|
593
|
-
* @Hidden()
|
|
594
|
-
* hiddenRoute(){
|
|
595
|
-
*
|
|
596
|
-
* }
|
|
597
|
-
* }
|
|
598
|
-
*
|
|
599
|
-
* @Controller('/')
|
|
600
|
-
* @Hidden()
|
|
601
|
-
* export class Ctrl {
|
|
602
|
-
* @Get('/')
|
|
603
|
-
* hiddenRoute() {
|
|
604
|
-
*
|
|
605
|
-
* }
|
|
606
|
-
* @Get('/2')
|
|
607
|
-
* hiddenRoute2() {
|
|
608
|
-
*
|
|
609
|
-
* }
|
|
610
|
-
* }
|
|
611
|
-
* ```
|
|
612
|
-
*
|
|
613
|
-
* @decorator
|
|
614
|
-
* @swagger
|
|
615
|
-
*/
|
|
616
|
-
|
|
617
|
-
function Hidden() {
|
|
618
|
-
return schema.Hidden();
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
exports.Docs = Docs;
|
|
622
|
-
exports.Hidden = Hidden;
|
|
623
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils/getSpecType.ts","../src/utils/mapOpenSpecInfo.ts","../src/utils/mapOpenSpec2.ts","../src/utils/mapOpenSpec3.ts","../src/utils/mapOpenSpec.ts","../src/utils/matchPath.ts","../src/utils/includeRoute.ts","../src/services/SwaggerService.ts","../src/middlewares/cssMiddleware.ts","../src/middlewares/indexMiddleware.ts","../src/middlewares/jsMiddleware.ts","../src/middlewares/redirectMiddleware.ts","../src/SwaggerModule.ts","../src/decorators/docs.ts","../src/decorators/hidden.ts"],"sourcesContent":["import {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"@tsed/schema\";\n\n/**\n * @ignore\n * @param version\n */\nexport function getSpecType(version: string) {\n return version.startsWith(\"3.\") ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n\n/**\n * @ignore\n * @param spec\n */\nexport function getSpecTypeFromSpec(spec: Partial<OpenSpec2 | OpenSpec3>) {\n return \"openapi\" in spec ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n","import {cleanObject} from \"@tsed/core\";\nimport {OpenSpecInfo} from \"@tsed/openspec\";\n\n/**\n * @ignore\n * @param info\n */\nexport function mapOpenSpecInfo(info: Partial<OpenSpecInfo>): OpenSpecInfo {\n const {title, description, version, termsOfService, contact, license} = info;\n\n return cleanObject({\n version,\n title,\n description,\n termsOfService,\n contact,\n license\n });\n}\n","import {getValue, uniq} from \"@tsed/core\";\nimport {OpenSpec2} from \"@tsed/openspec\";\nimport {mapOpenSpecInfo} from \"./mapOpenSpecInfo\";\n\n/**\n * @ignore\n * @param spec\n * @param version\n * @param specVersion\n * @param acceptMimes\n */\nexport function mapOpenSpec2(\n spec: Partial<OpenSpec2>,\n {version, specVersion, acceptMimes = [\"application/json\"]}: any\n): Partial<OpenSpec2> {\n const {\n paths,\n security,\n tags,\n host,\n basePath,\n schemes,\n consumes = [],\n produces = [\"application/json\"],\n definitions,\n parameters,\n responses,\n securityDefinitions,\n externalDocs\n } = spec;\n\n return {\n swagger: specVersion,\n consumes: uniq([...acceptMimes, ...consumes]),\n produces: uniq<string>([...produces]),\n info: mapOpenSpecInfo(getValue(spec, \"info\", {})),\n paths,\n host,\n basePath,\n schemes,\n definitions,\n parameters,\n responses,\n security,\n securityDefinitions,\n tags,\n externalDocs\n };\n}\n","import {getValue} from \"@tsed/core\";\nimport {OpenSpec3} from \"@tsed/openspec\";\nimport {mapOpenSpecInfo} from \"./mapOpenSpecInfo\";\n\n/**\n * @ignore\n * @param spec\n * @param version\n * @param specVersion\n */\nexport function mapOpenSpec3(spec: any, {specVersion}: any): Partial<OpenSpec3> {\n const {servers, paths, components, security, tags, externalDocs} = spec;\n\n return {\n openapi: specVersion,\n info: mapOpenSpecInfo(getValue(spec, \"info\", {})),\n servers,\n paths,\n components,\n security,\n tags,\n externalDocs\n };\n}\n","import {getValue, setValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3, OpenSpecVersions} from \"@tsed/openspec\";\nimport {mergeSpec, SpecTypes} from \"@tsed/schema\";\nimport {getSpecType} from \"./getSpecType\";\nimport {mapOpenSpec2} from \"./mapOpenSpec2\";\nimport {mapOpenSpec3} from \"./mapOpenSpec3\";\n\n/**\n * @ignore\n * @param spec\n * @param fileSpec\n * @param version\n * @param acceptMimes\n * @param specVersion\n */\nexport function mapOpenSpec(spec: any, {fileSpec, acceptMimes, specVersion, version}: any): Partial<OpenSpec2 | OpenSpec3> {\n specVersion = specVersion || getValue<OpenSpecVersions>(spec, \"openapi\", getValue(spec, \"swagger\", \"2.0\"));\n\n const options = {\n specVersion,\n acceptMimes\n };\n\n switch (getSpecType(specVersion)) {\n case SpecTypes.OPENAPI:\n spec = mapOpenSpec3(spec, options);\n fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;\n break;\n default:\n case SpecTypes.SWAGGER:\n spec = mapOpenSpec2(spec, options);\n fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;\n break;\n }\n\n spec = mergeSpec(spec, fileSpec);\n\n setValue(spec, \"info.title\", getValue(spec, \"info.title\", \"Api documentation\"));\n setValue(spec, \"info.version\", getValue(spec, \"info.version\", version));\n\n return spec;\n}\n","import micromatch from \"micromatch\";\n\nexport function matchPath(path: string, patterns?: string[]) {\n return patterns && patterns.length ? micromatch.isMatch(path, patterns) : true;\n}\n","import {ControllerProvider} from \"@tsed/common\";\nimport {matchPath} from \".\";\nimport {SwaggerSettings} from \"..\";\n\nexport function includeRoute(route: string, provider: ControllerProvider, conf: SwaggerSettings): boolean {\n const hidden = provider.store.get(\"hidden\");\n const docs = provider.store.get(\"docs\") || [];\n const {doc, pathPatterns} = conf;\n const inDoc = doc && docs.indexOf(doc) > -1;\n const pathPatternMatch = pathPatterns && matchPath(route, pathPatterns);\n\n if (hidden) {\n return false;\n }\n\n if (!doc && !pathPatterns) {\n return true;\n }\n\n return !!(inDoc || pathPatternMatch);\n}\n","import {Configuration, ControllerProvider, Injectable, InjectorService, Platform} from \"@tsed/common\";\nimport {getValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {getSpec, mergeSpec, SpecSerializerOptions} from \"@tsed/schema\";\nimport Fs from \"fs\";\nimport {SwaggerOS2Settings, SwaggerOS3Settings, SwaggerSettings} from \"../interfaces/SwaggerSettings\";\nimport {getSpecTypeFromSpec} from \"../utils/getSpecType\";\nimport {includeRoute} from \"../utils/includeRoute\";\nimport {mapOpenSpec} from \"../utils/mapOpenSpec\";\n\n@Injectable()\nexport class SwaggerService {\n #specs: Map<string, OpenSpec3 | OpenSpec2> = new Map();\n\n constructor(\n private injectorService: InjectorService,\n private platform: Platform,\n @Configuration() private configuration: Configuration\n ) {}\n\n /**\n * Generate Spec for the given configuration\n * @returns {Spec}\n */\n public getOpenAPISpec(conf: SwaggerOS3Settings): OpenSpec3;\n public getOpenAPISpec(conf: SwaggerOS2Settings): OpenSpec2;\n public getOpenAPISpec(conf: SwaggerSettings): OpenSpec2;\n public getOpenAPISpec(conf: SwaggerSettings) {\n if (!this.#specs.has(conf.path)) {\n const defaultSpec: any = this.getDefaultSpec(conf);\n const specType = getSpecTypeFromSpec(defaultSpec);\n let finalSpec: any = {};\n\n const options: SpecSerializerOptions = {\n paths: {},\n tags: [],\n schemas: {},\n specType,\n operationIdFormatter: conf.operationIdFormatter,\n operationIdPattern: conf.operationIdPattern,\n append(spec: any) {\n finalSpec = mergeSpec(finalSpec, spec);\n }\n };\n\n this.platform.getMountedControllers().forEach(({route, provider}) => {\n if (includeRoute(route, provider, conf)) {\n const spec = this.buildRoutes(provider, {\n ...options,\n rootPath: route.replace(provider.path, \"\")\n });\n\n options.append(spec);\n }\n });\n\n this.#specs.set(conf.path, mergeSpec(defaultSpec, finalSpec) as any);\n }\n\n return this.#specs.get(conf.path);\n }\n\n /**\n * Return the global api information.\n */\n protected getDefaultSpec(conf: Partial<SwaggerSettings>): Partial<OpenSpec2 | OpenSpec3> {\n const {version = \"1.0.0\", acceptMimes} = this.configuration;\n const {specPath, specVersion} = conf;\n const fileSpec: Partial<OpenSpec2 | OpenSpec3> = specPath ? this.readSpecPath(specPath) : {};\n\n return mapOpenSpec(getValue(conf, \"spec\", {}), {\n fileSpec,\n version,\n specVersion,\n acceptMimes\n });\n }\n\n protected readSpecPath(path: string) {\n path = this.configuration.resolve(path);\n if (Fs.existsSync(path)) {\n const json = Fs.readFileSync(path, {encoding: \"utf8\"});\n /* istanbul ignore else */\n if (json !== \"\") {\n return JSON.parse(json);\n }\n }\n\n return {};\n }\n\n /**\n *\n * @param ctrl\n * @param options\n */\n protected buildRoutes(ctrl: ControllerProvider, options: SpecSerializerOptions) {\n const rootPath = options.rootPath + ctrl.path;\n\n ctrl.children\n .map((ctrl) => this.injectorService.getProvider(ctrl))\n .forEach((provider: ControllerProvider) => {\n if (!provider.store.get(\"hidden\")) {\n const spec = this.buildRoutes(provider, {\n ...options,\n rootPath\n });\n\n options.append(spec);\n }\n });\n\n return getSpec(ctrl.token, options);\n }\n}\n","import {PlatformContext} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {resolve} from \"path\";\n\n/**\n * @ignore\n * @param path\n */\nexport function cssMiddleware(path: string) {\n return (ctx: PlatformContext) => {\n const content = Fs.readFileSync(resolve(path), {encoding: \"utf8\"});\n ctx.response\n .setHeaders({\n \"Content-Type\": \"text/css\"\n })\n .status(200)\n .body(content);\n };\n}\n","import {PlatformContext} from \"@tsed/common\";\nimport {SwaggerSettings} from \"../interfaces/SwaggerSettings\";\n\n/**\n * @ignore\n * @param viewPath\n * @param conf\n */\nexport function indexMiddleware(viewPath: string, conf: SwaggerSettings & {urls: string[]}) {\n return async (ctx: PlatformContext) => {\n const {path = \"/\", options = {}, showExplorer, cssPath, jsPath, urls} = conf;\n\n ctx.response.body(\n await ctx.response.render(viewPath, {\n spec: {},\n url: `${path}/swagger.json`,\n urls,\n showExplorer,\n cssPath,\n jsPath,\n swaggerOptions: options\n })\n );\n };\n}\n","import {PlatformContext} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {resolve} from \"path\";\n\n/**\n * @ignore\n * @param path\n */\nexport function jsMiddleware(path: string) {\n return (ctx: PlatformContext) => {\n const content = Fs.readFileSync(resolve(path), {encoding: \"utf8\"});\n ctx.response.setHeaders({\"Content-Type\": \"application/javascript\"}).status(200).body(content);\n };\n}\n","import {PlatformContext} from \"@tsed/common\";\n\n/**\n * @ignore\n * @param path\n */\nexport function redirectMiddleware(path: string) {\n return (ctx: PlatformContext) => {\n if (ctx.request.url === path && !ctx.request.url.match(/\\/$/)) {\n ctx.response.redirect(302, `${path}/`);\n }\n };\n}\n","import {\n BeforeRoutesInit,\n Configuration,\n Inject,\n InjectorService,\n Module,\n normalizePath,\n OnReady,\n PlatformApplication,\n PlatformContext,\n PlatformRouter,\n useCtxHandler\n} from \"@tsed/common\";\nimport Fs from \"fs\";\nimport {join} from \"path\";\nimport {SwaggerSettings} from \"./interfaces\";\nimport {cssMiddleware} from \"./middlewares/cssMiddleware\";\nimport {indexMiddleware} from \"./middlewares/indexMiddleware\";\nimport {jsMiddleware} from \"./middlewares/jsMiddleware\";\nimport {redirectMiddleware} from \"./middlewares/redirectMiddleware\";\nimport {SwaggerService} from \"./services/SwaggerService\";\n\nconst swaggerUiPath = require(\"swagger-ui-dist\").absolutePath();\n\n/**\n * @ignore\n */\n@Module()\nexport class SwaggerModule implements BeforeRoutesInit, OnReady {\n @Inject()\n injector: InjectorService;\n\n @Inject()\n app: PlatformApplication;\n\n @Configuration()\n configuration: Configuration;\n\n @Inject()\n swaggerService: SwaggerService;\n\n private loaded = false;\n\n get settings() {\n return ([] as SwaggerSettings[]).concat(this.configuration.get<SwaggerSettings[]>(\"swagger\")).filter((o) => !!o);\n }\n\n /**\n *\n */\n $beforeRoutesInit() {\n if (this.loaded) {\n return;\n }\n\n const urls: any[] = this.getUrls();\n\n this.settings.forEach((conf: SwaggerSettings) => {\n const {path = \"/\"} = conf;\n\n this.app.get(path, useCtxHandler(redirectMiddleware(path)));\n this.app.use(path, this.createRouter(conf, urls));\n });\n\n this.loaded = true;\n }\n\n $onReady() {\n // istanbul ignore next\n if (this.configuration.getBestHost) {\n const host = this.configuration.getBestHost();\n\n if (!host) {\n return;\n }\n\n const displayLog = (conf: SwaggerSettings) => {\n const {path = \"/\", fileName = \"swagger.json\", doc} = conf;\n\n let url = \"/\";\n\n if (host) {\n url = typeof host.port === \"number\" ? `${host.protocol}://${host.address}:${host.port}` : \"\";\n }\n\n this.injector.logger.info(`[${doc || \"default\"}] Swagger JSON is available on ${url}${normalizePath(path, fileName)}`);\n this.injector.logger.info(`[${doc || \"default\"}] Swagger UI is available on ${url}${path}/`);\n };\n\n this.settings.forEach((conf) => {\n displayLog(conf);\n });\n }\n\n this.generateSpecFiles();\n }\n\n generateSpecFiles() {\n return Promise.all(\n this.settings.map((conf) => {\n const {outFile} = conf;\n\n if (outFile) {\n const spec = this.swaggerService.getOpenAPISpec(conf);\n return Fs.writeFile(outFile, JSON.stringify(spec, null, 2), {encoding: \"utf8\"}, () => {});\n }\n })\n );\n }\n\n private getUrls() {\n return this.settings.reduce((acc: any[], conf) => {\n const {path = \"/\", fileName = \"swagger.json\", doc, hidden} = conf;\n\n if (!hidden) {\n acc.push({url: normalizePath(path, fileName), name: doc || path});\n }\n\n return acc;\n }, []);\n }\n\n /**\n *\n * @param conf\n * @param urls\n */\n private createRouter(conf: SwaggerSettings, urls: string[]) {\n const {disableSpec = false, fileName = \"swagger.json\", cssPath, jsPath, viewPath = join(__dirname, \"../views/index.ejs\")} = conf;\n const router = PlatformRouter.create(this.injector);\n\n if (!disableSpec) {\n router.get(normalizePath(\"/\", fileName), useCtxHandler(this.middlewareSwaggerJson(conf)));\n }\n\n if (viewPath) {\n if (cssPath) {\n router.get(\"/main.css\", useCtxHandler(cssMiddleware(cssPath)));\n }\n\n if (jsPath) {\n router.get(\"/main.js\", useCtxHandler(jsMiddleware(jsPath)));\n }\n\n router.get(\"/\", useCtxHandler(indexMiddleware(viewPath, {urls, ...conf})));\n router.statics(\"/\", {root: swaggerUiPath});\n }\n\n return router;\n }\n\n private middlewareSwaggerJson(conf: SwaggerSettings) {\n return (ctx: PlatformContext) => {\n ctx.response.status(200).body(this.swaggerService.getOpenAPISpec(conf));\n };\n }\n}\n","import {StoreMerge} from \"@tsed/core\";\n\n/**\n * Set the type documentation for this class.\n *\n * See [swagger documentation](/tutorials/swagger.html)\n *\n * @decorator\n * @swagger\n * @param docs\n */\nexport function Docs(...docs: string[]) {\n return StoreMerge(\"docs\", docs);\n}\n","import {Hidden as H} from \"@tsed/schema\";\n\n/**\n * Disable documentation for the class and his endpoint.\n *\n * ````typescript\n * @Controller('/')\n * export class Ctrl {\n *\n * @Get('/')\n * @Hidden()\n * hiddenRoute(){\n *\n * }\n * }\n *\n * @Controller('/')\n * @Hidden()\n * export class Ctrl {\n * @Get('/')\n * hiddenRoute() {\n *\n * }\n * @Get('/2')\n * hiddenRoute2() {\n *\n * }\n * }\n * ```\n *\n * @decorator\n * @swagger\n */\nexport function Hidden() {\n return H();\n}\n"],"names":["getSpecType","version","startsWith","SpecTypes","OPENAPI","SWAGGER","getSpecTypeFromSpec","spec","mapOpenSpecInfo","info","title","description","termsOfService","contact","license","cleanObject","mapOpenSpec2","specVersion","acceptMimes","paths","security","tags","host","basePath","schemes","consumes","produces","definitions","parameters","responses","securityDefinitions","externalDocs","swagger","uniq","getValue","mapOpenSpec3","servers","components","openapi","mapOpenSpec","fileSpec","options","mergeSpec","setValue","matchPath","path","patterns","length","micromatch","isMatch","includeRoute","route","provider","conf","hidden","store","get","docs","doc","pathPatterns","inDoc","indexOf","pathPatternMatch","SwaggerService","constructor","injectorService","platform","configuration","Map","getOpenAPISpec","has","defaultSpec","getDefaultSpec","specType","finalSpec","schemas","operationIdFormatter","operationIdPattern","append","getMountedControllers","forEach","buildRoutes","rootPath","replace","set","specPath","readSpecPath","resolve","Fs","existsSync","json","readFileSync","encoding","JSON","parse","ctrl","children","map","getProvider","getSpec","token","Injectable","__param","Configuration","InjectorService","Platform","cssMiddleware","ctx","content","response","setHeaders","status","body","indexMiddleware","viewPath","showExplorer","cssPath","jsPath","urls","render","url","swaggerOptions","jsMiddleware","redirectMiddleware","request","match","redirect","swaggerUiPath","require","absolutePath","SwaggerModule","settings","concat","filter","o","$beforeRoutesInit","loaded","getUrls","app","useCtxHandler","use","createRouter","$onReady","getBestHost","displayLog","fileName","port","protocol","address","injector","logger","normalizePath","generateSpecFiles","Promise","all","outFile","swaggerService","writeFile","stringify","reduce","acc","push","name","disableSpec","join","__dirname","router","PlatformRouter","create","middlewareSwaggerJson","statics","root","__decorate","Inject","PlatformApplication","Module","Docs","StoreMerge","Hidden","H"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;SAIgBA,YAAYC;AAC1B,SAAOA,OAAO,CAACC,UAAR,CAAmB,IAAnB,IAA2BC,gBAAS,CAACC,OAArC,GAA+CD,gBAAS,CAACE,OAAhE;AACD;AAED;;;;;SAIgBC,oBAAoBC;AAClC,SAAO,aAAaA,IAAb,GAAoBJ,gBAAS,CAACC,OAA9B,GAAwCD,gBAA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