-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcollectionConverter.html
66 lines (55 loc) · 2.23 KB
/
collectionConverter.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
<head>
<title>Postman collection to Stoplight Converter</title>
<meta charset="utf-8">
<script src="./postman2stoplight.js"></script>
</head>
<body>
<script type="text/javascript">
function convertFile(fileInput, outputArea) {
// Check if a file is selected
if(fileInput.files.length > 0) {
// Check for JSON extension
fileType = fileInput.files[0].name.split('.');
fileType = fileType[fileType.length - 1].toLowerCase();
if (fileType != 'json') {
outputArea.value = JSON.stringify({ "error" : "The file must be a JSON file." }, 2, 2);
return;
}
var reader = new FileReader();
reader.addEventListener('load', function() {
try {
var inputCollection = JSON.parse(reader.result);
var convertedResult = convertPostman2Stoplight(inputCollection);
outputArea.value = JSON.stringify(convertedResult, 2, 2);
outputArea.style.height="500px";
} catch (e) {
outputArea.value = JSON.stringify({ "error" : "The input is not JSON well-formed.", "message" : e.message}, 2, 2);
console.log(e.stack);
return;
}
});
reader.readAsText(fileInput.files[0]);
} else {
outputArea.value = JSON.stringify({ "error" : "Please choose a JSON file." }, 2, 2);
return;
}
}
</script>
<h1>Postman to Stoplight converter</h1>
<strong>Source : </strong><a href="https://github.com/ntiss/postmanToStoplightConverter">View this project on Github</a><br/>
<strong>License : </strong><a href="https://github.com/ntiss/postmanToStoplightConverter/blob/master/LICENSE">Apache License V2</a><br/>
<strong>Disclaimer : </strong> This tool is provided "as is" and "with all faults". You are solely responsible for determining whether this tool applies to your context.
<br/><br/>
Input :<br/>
<div style="width:95%;border:1px #999 solid;padding:10px">
<input id="inputFile" type="file" />
<br/><br/>
<input type="button" onclick="convertFile(document.getElementById('inputFile'), document.getElementById('outputCollection'))" value="Convert to Stoplight"/>
</div>
<br/><br/>
Output :<br/>
<textarea id="outputCollection" style="width:95%;height:200px;border:1px #999 solid;margin:0;padding:10px" readonly="true"></textarea>
</body>
</html>