forked from rbren/fhir-swagger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
31 lines (29 loc) · 1019 Bytes
/
index.js
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
var Request = require('request');
var Converter = require('./lib/conformance-to-swagger.js');
module.exports = function(options, callback) {
callback = callback || function(err) {if (err) throw err};
var headers = {};
var jwt = options.jwt;
var auth = options.authorization;
if (jwt) {
headers.Authorization = 'Bearer ' + options.jwt;
} else if (auth) {
var authString = auth.username + ':' + auth.password;
authString = new Buffer(authString).toString('base64');
headers.Authorization = 'Basic ' + authString;
}
Request({
rejectUnauthorized: options.reject_unauthorized,
url: options.fhir_url + options.conformance_path,
headers: headers,
json: true,
}, function(err, resp, body) {
if (err) return callback(err);
var swagger = Converter.convert(options.fhir_url, body);
if (auth) {
swagger.securityDefinitions = swagger.securityDefinitions || {};
swagger.securityDefinitions.Basic = {type: 'basic'};
}
callback(null, swagger);
})
}