js-json-schema
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -9,3 +9,3 @@ var jsonschema = require('./index'); | ||
}; | ||
User.prototype.attributes = ["name", "email", "password", "address:Address", "active:enum Active,Inactive"]; | ||
User.prototype.attributes = ["name", "email", "password", "address:Address[]", "active:enum Active,Inactive"]; | ||
User.prototype.extend = {}; | ||
@@ -12,0 +12,0 @@ User.prototype.extend.staffUser = ["staffId", "department"]; |
@@ -12,12 +12,14 @@ var fs = require('fs'), helper = require('./commons'); | ||
if (typeInstance.extend[q]) { | ||
return q.capitalize() + type.capitalize() + options.ext; | ||
return q.capitalize() + type.capitalize(); | ||
} | ||
} else { | ||
return type.capitalize() + options.ext; | ||
return type.capitalize(); | ||
} | ||
} | ||
} | ||
return type.capitalize() + options.ext; | ||
return type.capitalize(); | ||
}; | ||
var generator = function (instance, name) { | ||
@@ -43,18 +45,3 @@ | ||
schema.properties[name].description = description + name; | ||
if (type.toLowerCase() === "enum") { | ||
schema.properties[name].enum = element.enum; | ||
} else { | ||
schema.properties[name].type = type.toLowerCase(); | ||
if (type.toLowerCase() === "number") { | ||
schema.properties[name].minimum = 0; | ||
} | ||
if (type.toLowerCase() === "date") { | ||
schema.properties[name].type = "string"; | ||
schema.properties[name].format = "date"; | ||
} | ||
if (!helper.isDefaultType(schema.properties[name].type.toLowerCase())) { | ||
schema.properties[name].type = "object"; | ||
schema.properties[name]["$ref"] = findReference(type, category); | ||
} | ||
} | ||
helper.handleTypes(schema, name, type, element, category, options, findReference); | ||
} | ||
@@ -61,0 +48,0 @@ return schema; |
@@ -13,6 +13,13 @@ if (String.prototype.capitalize === undefined) { | ||
} | ||
if (String.prototype.endsWith === undefined) { | ||
String.prototype.endsWith = function (text) { | ||
text = text.replace(".", "\\."); | ||
text = text.replace("[", "\\["); | ||
text = text.replace("]", "\\]"); | ||
return new RegExp(text+"$").test(this) | ||
}; | ||
} | ||
var varType = /([a-zA-Z]+):([A-Za-z\s,_\[\]]+)/; | ||
var varType = /([a-zA-Z]+):([A-Za-z\s,_]+)/; | ||
var isDefaultType = function (typeName) { | ||
@@ -55,2 +62,26 @@ var jsonTypes = ['integer', 'number', 'object', 'array', 'boolean', 'string']; | ||
var handleTypes = function(schema, name, type, element, category, options, refFinder) { | ||
if (type.toLowerCase() === "enum") { | ||
schema.properties[name].enum = element.enum; | ||
} else { | ||
schema.properties[name].type = type.toLowerCase(); | ||
if (type.toLowerCase() === "number") { | ||
schema.properties[name].minimum = 0; | ||
} | ||
if (type.toLowerCase() === "date") { | ||
schema.properties[name].type = "string"; | ||
schema.properties[name].format = "date"; | ||
} | ||
if (!isDefaultType(schema.properties[name].type.toLowerCase())) { | ||
var refType = refFinder(type, category); | ||
if (refType.endsWith("[]")) { | ||
schema.properties[name].type = "array"; | ||
schema.properties[name]["items"] = {"$ref": refType.slice(0, refType.length - 2) + options.ext}; | ||
} else { | ||
schema.properties[name].type = "object"; | ||
schema.properties[name]["$ref"] = refType + options.ext; | ||
} | ||
} | ||
} | ||
}; | ||
@@ -60,3 +91,4 @@ module.exports = { | ||
inspect: inspect, | ||
cleanser: cleanser | ||
cleanser: cleanser, | ||
handleTypes: handleTypes | ||
}; |
@@ -5,2 +5,6 @@ var fs = require('fs'), helper = require('./commons'); | ||
var findReference = function (type) { | ||
return type.capitalize(); | ||
}; | ||
var generator = function (instance, name) { | ||
@@ -25,18 +29,3 @@ | ||
schema.properties[name].description = description + name; | ||
if (type.toLowerCase() === "enum") { | ||
schema.properties[name].enum = element.enum; | ||
} else { | ||
schema.properties[name].type = type.toLowerCase(); | ||
if (type.toLowerCase() === "number") { | ||
schema.properties[name].minimum = 0; | ||
} | ||
if (type.toLowerCase() === "date") { | ||
schema.properties[name].type = "string"; | ||
schema.properties[name].format = "date"; | ||
} | ||
if (!helper.isDefaultType(schema.properties[name].type.toLowerCase())) { | ||
schema.properties[name].type = 'object'; | ||
schema.properties[name]["$ref"] = type.capitalize() + options.ext; | ||
} | ||
} | ||
helper.handleTypes(schema, name, type, element, '', options, findReference) | ||
} | ||
@@ -43,0 +32,0 @@ }; |
{ | ||
"name": "js-json-schema", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "create json schema from javascript configuration", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16410
14
358
0