-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (35 loc) · 1.1 KB
/
Copy pathindex.js
File metadata and controls
46 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const Swagger = require('swagger-client');
const deasync = require('deasync');
const cachedClients = {};
function generateClient(options) {
const client = new Swagger(options);
while (!(client instanceof Swagger) && client.inspect().state === 'pending') {
deasync.sleep(1);
}
return client.valueOf();
}
/**
* Create a swagger-client synchronously.
*
* @param {String|Object} options URL to swagger specification or object with options that will be passed to swagger-client constructor.
* @param {Boolean=} ignoreCache Created new swagger-client and don't cache it (default: false).
*/
function returnClient(options, ignoreCache) {
if (typeof options === 'string') {
options = {
url: options,
usePromise: true
};
}
if (ignoreCache === true) {
return generateClient(options);
}
const optionsJSON = JSON.stringify(options);
if (cachedClients[optionsJSON] instanceof Swagger) {
return cachedClients[optionsJSON];
} else {
cachedClients[optionsJSON] = generateClient(options);
return cachedClients[optionsJSON];
}
}
module.exports = returnClient;