Skip to content

Instantly share code, notes, and snippets.

@Marak

Marak/partial.js Secret

Created September 2, 2012 04:36
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 Marak/bf21229c7a1d6ae02884 to your computer and use it in GitHub Desktop.
Save Marak/bf21229c7a1d6ae02884 to your computer and use it in GitHub Desktop.
starting to define schema for Resource
var description = {
"default": "",
"description": "the description of the property"
};
var message = {
"default": "",
"description": "custom error message to be shown on error"
};
var conform = {
"default": function(val) {
return val;
},
"description": "value must satisify this custom method"
};
var fakeSchema = {
"String": {
"default": {
"default": "",
"description": "the default value ( a string )"
},
"description": description,
"format": {
"default": "",
"description": "a pre-defined format the value should match",
"enum": ["email", "url"]
},
"message": message,
"minLength": {
"default": 0,
"description": "the minimum length of the string"
},
"maxLength": {
"default": 10,
"description": "the maximum length of the string"
},
"enum": {
"default": "[]",
"description": "value must be contained in this array"
},
"pattern": {
"default": new RegExp(),
"description": "value must satisify this regex pattern"
},
"conform": conform
},
"Number": {
"default": {
"default": 0,
"description": "the default value ( a number )"
},
"description": description,
"message": message,
"minimum": {
"default": 0,
"description": "the default value ( a number )"
},
"maximum": {
"default": 0,
"description": "the default value ( a number )"
},
"conform": conform
},
"Boolean": {
"default": {
"default": false,
"description": "the default value ( a boolean )"
},
"description": description,
"message": message
},
"Array": {
"default": {
"default": "[]",
"description": "the default value ( an array )"
},
"description": description,
"message": message
},
"Object": {
"default": {
"default": "{}",
"description": "the default value ( an object )"
},
"description": description,
"message": message
}
};
@raix
Copy link

raix commented Sep 2, 2012

Number actually have "within" defined as an array of two: minimum, maximum
String have "Length" likewise an array :minLength, maxLength - have to say that they fail
The exclusiveMinimum.. Are actually implemented in revalidator, so should easily be in the resourceful.
Sanitize is currently a chained function if using bultins (abs, upper...) , but a property if you customize
I made https://github.com/raix/resourceful/wiki/Define-resources where i tried to (tried some markdown, not quite there...) but then i discovered the revalidator api witch speakes of the json schema. Well still learning, kind of a newbe here :)

@Marak
Copy link
Author

Marak commented Sep 4, 2012

There's a bunch of stuff missing and wrong here. This isn't for review, it was a reference for myself.

No need to point it out. It's why I made a ticket and linked this from flatiron/resourceful#115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment