Skip to content

Instantly share code, notes, and snippets.

@MathRobin
Created October 31, 2019 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MathRobin/eeddc0b2c7621b1935bdd4c4967f9796 to your computer and use it in GitHub Desktop.
Save MathRobin/eeddc0b2c7621b1935bdd4c4967f9796 to your computer and use it in GitHub Desktop.
object to json oas
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