Added option to use number type instead of integer, fixed interface typo

This commit is contained in:
RogerBernardo
2017-05-10 11:07:00 -03:00
parent 8434449ad2
commit 3529a67577
3 changed files with 13 additions and 7 deletions

View File

@@ -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 * Allows mock values to be added as example in description
## TO-DO List ## TO-DO List
* Configurable valid types/formats
* Reflection for detecting reusable definitions * Reflection for detecting reusable definitions

View File

@@ -58,6 +58,7 @@
<textarea readonly="true" id="Swagger" rows="20" cols="85" placeholder="Here is your Swagger"></textarea> <textarea readonly="true" id="Swagger" rows="20" cols="85" placeholder="Here is your Swagger"></textarea>
<br> <br>
<p>Add values as examples: <input type="checkbox" id="requestExamples"></p> <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: <p>Convert null values to:
<select id="nullType"> <select id="nullType">
<option value="string" selected="">String</option> <option value="string" selected="">String</option>
@@ -66,7 +67,7 @@
<option value="boolean">Boolean</option> <option value="boolean">Boolean</option>
</select> </select>
</p> </p>
<p>Genreate YAML: <input type="checkbox" id="YAML"></p> <p>Output as YAML: <input type="checkbox" id="yamlOut"></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

@@ -1,7 +1,8 @@
function convert() { function convert() {
'use strict'; 'use strict';
var inJSON, outSwagger, tabCount, indentator // ---- Global variables ----
; var inJSON, outSwagger, tabCount, indentator;
// ---- Functions definitions ---- // ---- Functions definitions ----
function changeIndentation (count) { function changeIndentation (count) {
/* /*
@@ -57,7 +58,7 @@ function convert() {
-outSwagger -outSwagger
*/ */
if (num % 1 === 0) { if (num % 1 === 0 && !document.getElementById("noInt").checked) {
outSwagger += indentator + '"type": "integer",'; outSwagger += indentator + '"type": "integer",';
if (num < 2147483647 && num > -2147483647) { if (num < 2147483647 && num > -2147483647) {
outSwagger += indentator + '"format": "int32"'; outSwagger += indentator + '"format": "int32"';
@@ -150,6 +151,11 @@ function convert() {
}; };
function format(value, yaml) { function format(value, yaml) {
/*
Convert JSON to YAML if yaml checkbox is checked
Global variables updated:
NONE
*/
if (yaml) { if (yaml) {
return value.replace(/[{},"]+/g, '').replace(/\t/g, ' ').replace(/(^ *\n)/gm, ''); return value.replace(/[{},"]+/g, '').replace(/\t/g, ' ').replace(/(^ *\n)/gm, '');
} else { } else {
@@ -186,6 +192,6 @@ function convert() {
changeIndentation(tabCount-1); changeIndentation(tabCount-1);
outSwagger += indentator + '}'; 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);
} }