Created
October 31, 2019 10:06
-
-
Save MathRobin/eeddc0b2c7621b1935bdd4c4967f9796 to your computer and use it in GitHub Desktop.
object to json oas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doc (obj){ | |
var res = {}; | |
_.each(obj, function (val, key) { | |
if(_.isArray(val)) { | |
res[key] = {"type": "array", items:{type:"object","properties": doc(val)}}; | |
} else if(_.isObject(val)) { | |
res[key] = {"type": "object","properties": doc(val)}; | |
} else if(_.isString(val)){ | |
res[key] = {type:'string'}; | |
} else if(_.isInteger(val)){ | |
res[key] = {type:'integer'}; | |
} else if(_.isNumber(val)){ | |
res[key] = {type:'number'}; | |
} | |
}); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment