-
Notifications
You must be signed in to change notification settings - Fork 36
/
server.js
42 lines (39 loc) · 1.04 KB
/
server.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
32
33
34
35
36
37
38
39
40
41
42
var express = require("express");
var app = express();
var yaml = require("yamljs");
var fs = require("fs");
var refParser = require("json-schema-ref-parser");
var args = process.argv.slice(2);
app.get("/", function (req, res) {
res.sendFile(__dirname + "/local.html");
});
app.get("/openapifile", function (req, res) {
if (args[0] == "json") {
fs.readFile("openapi.json", "utf8", function (err, data) {
var json = JSON.parse(data);
if (err) throw err;
refParser.dereference(json, function (err, schema) {
if (err) {
console.error(err);
} else {
res.send(schema);
}
});
});
} else {
fs.readFile("openapi.yml", "utf8", function (err, data) {
if (err) throw err;
var json = yaml.parse(data);
refParser.dereference(json, function (err, schema) {
if (err) {
console.error(err);
} else {
res.send(schema);
}
});
});
}
});
app.listen(3001, function () {
console.log("listening on http://localhost:3001");
});