-
Notifications
You must be signed in to change notification settings - Fork 95
/
index.html
98 lines (95 loc) · 2.83 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Swagger Generator</title>
<script src="swaggerGen.js" type="text/javascript"></script>
<script>
function init() {
//Handle tabs inside JSON textarea
let txtArea = document.getElementById('JSON');
txtArea.onkeydown = function(e){
if(e.keyCode==9 || e.which==9){
e.preventDefault();
let s = this.selectionStart;
this.value = this.value.substring(0,this.selectionStart) + "\t" + this.value.substring(this.selectionEnd);
this.selectionEnd = s+1;
}
}
};
</script>
<style>
textarea{
display: inline-block;
margin: 10px;
}
button{
display: inline-block;
}
</style>
</head>
<body onload="init();">
<h1>Swagger Definition Objects Generator</h1>
<p>Add your JSON mock to generate Swagger definition objects.</p>
<textarea id="JSON" rows="20" cols="55" placeholder="Type your JSON">
{
"numbersMock": {
"smallInt": -20,
"bigInt": 2147483647,
"unsafeInt": 9999999999999999,
"notInt": 12.2
},
"stringsMock": {
"stringTest": "Hello World",
"isoDate": "1999-12-31",
"isoDateTime": "1999-12-31T23:59:59Z"
},
"objectsMock": {
"child": {"child": true},
"childList": [{"child": true}],
"childMatrix": [[{"child": true}]],
"nullable": null
}
}
</textarea>
<button type="button" onclick="convert()">Convert</button>
<textarea readonly id="Swagger" rows="20" cols="85" placeholder="Here is your Swagger"></textarea>
<br>
<p>Add values as examples: <input type="checkbox" id="requestExamples"></p>
<p>Convert integer values to number: <input type="checkbox" id="noInt"></p>
<p>Convert null values to:
<select id="nullType">
<option value="string" selected="">String</option>
<option value="number">Number</option>
<option value="integer">Integer</option>
<option value="boolean">Boolean</option>
</select>
</p>
<p>Output as YAML: <input type="checkbox" id="yamlOut"></p>
<hr>
<p>Feel like collaborating? Clone the repository at <a target="_blank" href="https://github.com/Roger13/SwaggerGenerator">GitHub</a></p>
</body>
<script>
const options = ['requestExamples', 'noInt', 'nullType', 'yamlOut']
options.forEach(
option => document.getElementById(option).addEventListener("change", (event) => {
if (event.target.type === 'checkbox' ) {
if (!event.target.checked) {
return localStorage.removeItem(option)
}
return localStorage.setItem(option, 1)
}
return localStorage.setItem(option, event.target.value);
})
)
options.forEach(
option => {
const value = localStorage.getItem(option)
const input = document.getElementById(option)
if (value === null || !input) return
if (input.type === 'checkbox') return input.checked = true
return input.value = value
}
)
</script>
</html>