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>
</select>
</p>
<p>Genreate YAML: <input type="checkbox" id="YAML"></p>
<hr>
<p>Feel like colaborating? Clone the repository at <a target="_blank" href="https://github.com/Roger13/SwaggerGenerator">GitHub</a></p>

View File

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