mirror of
https://github.com/LukeHagar/SwagDefGen.git
synced 2025-12-06 04:21:38 +00:00
Added option to use number type instead of integer, fixed interface typo
This commit is contained in:
@@ -12,5 +12,4 @@ This is a tool to help building Swagger documentations. It converts JSON request
|
||||
* Allows mock values to be added as example in description
|
||||
|
||||
## TO-DO List
|
||||
* Configurable valid types/formats
|
||||
* Reflection for detecting reusable definitions
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
<textarea readonly="true" 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>
|
||||
@@ -66,7 +67,7 @@
|
||||
<option value="boolean">Boolean</option>
|
||||
</select>
|
||||
</p>
|
||||
<p>Genreate YAML: <input type="checkbox" id="YAML"></p>
|
||||
<p>Output as YAML: <input type="checkbox" id="yamlOut"></p>
|
||||
<hr>
|
||||
<p>Feel like colaborating? Clone the repository at <a target="_blank" href="https://github.com/Roger13/SwaggerGenerator">GitHub</a></p>
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
function convert() {
|
||||
'use strict';
|
||||
var inJSON, outSwagger, tabCount, indentator
|
||||
;
|
||||
// ---- Global variables ----
|
||||
var inJSON, outSwagger, tabCount, indentator;
|
||||
|
||||
// ---- Functions definitions ----
|
||||
function changeIndentation (count) {
|
||||
/*
|
||||
@@ -57,7 +58,7 @@ function convert() {
|
||||
-outSwagger
|
||||
*/
|
||||
|
||||
if (num % 1 === 0) {
|
||||
if (num % 1 === 0 && !document.getElementById("noInt").checked) {
|
||||
outSwagger += indentator + '"type": "integer",';
|
||||
if (num < 2147483647 && num > -2147483647) {
|
||||
outSwagger += indentator + '"format": "int32"';
|
||||
@@ -150,6 +151,11 @@ function convert() {
|
||||
};
|
||||
|
||||
function format(value, yaml) {
|
||||
/*
|
||||
Convert JSON to YAML if yaml checkbox is checked
|
||||
Global variables updated:
|
||||
NONE
|
||||
*/
|
||||
if (yaml) {
|
||||
return value.replace(/[{},"]+/g, '').replace(/\t/g, ' ').replace(/(^ *\n)/gm, '');
|
||||
} else {
|
||||
@@ -186,6 +192,6 @@ function convert() {
|
||||
changeIndentation(tabCount-1);
|
||||
outSwagger += indentator + '}';
|
||||
|
||||
var yaml = document.getElementById("YAML").checked;
|
||||
document.getElementById("Swagger").value = format(outSwagger, yaml);
|
||||
|
||||
document.getElementById("Swagger").value = format(outSwagger, document.getElementById("yamlOut").checked);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user