Add option to generate YAML

This commit is contained in:
Francesco Perrotti-Garcia
2017-04-12 15:21:28 -03:00
parent f57ed70c92
commit ffa5a43741
2 changed files with 11 additions and 1 deletions

View File

@@ -66,6 +66,7 @@
<option value="boolean">Boolean</option> <option value="boolean">Boolean</option>
</select> </select>
</p> </p>
<p>Genreate YAML: <input type="checkbox" id="YAML"></p>
<hr> <hr>
<p>Feel like colaborating? Clone the repository at <a target="_blank" href="https://github.com/Roger13/SwaggerGenerator">GitHub</a></p> <p>Feel like colaborating? Clone the repository at <a target="_blank" href="https://github.com/Roger13/SwaggerGenerator">GitHub</a></p>

View File

@@ -148,6 +148,14 @@ function convert() {
outSwagger += ' }'; outSwagger += ' }';
} }
}; };
function format(value, yaml) {
if (yaml) {
return value.replace(/[{},"]+/g, '').replace(/\t/g, ' ').replace(/(^[ \t]*\n)/gm, "");
} else {
return value
}
}
// ---- Execution begins here ---- // ---- Execution begins here ----
inJSON = document.getElementById("JSON").value; inJSON = document.getElementById("JSON").value;
@@ -178,5 +186,6 @@ function convert() {
changeIndentation(tabCount-1); changeIndentation(tabCount-1);
outSwagger += indentator + '}'; outSwagger += indentator + '}';
document.getElementById("Swagger").value = outSwagger; var yaml = document.getElementById("YAML").checked;
document.getElementById("Swagger").value = format(outSwagger, yaml);
} }