4
4
*
5
5
* Copyright (c) 2007 Kris Zyp SitePen (www.sitepen.com)
6
6
* Licensed under the MIT (MIT-LICENSE.txt) license.
7
- To use the validator call JSONSchema. validate with an instance object and an optional schema object.
7
+ To use the validator call the validate function with an instance object and an optional schema object.
8
8
If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
9
9
that schema will be used to validate and the schema parameter is not necessary (if both exist,
10
10
both validations will occur).
@@ -13,6 +13,8 @@ empty list will be returned. A validation error will have two properties:
13
13
"property" which indicates which property had the error
14
14
"message" which indicates what the error was
15
15
*/
16
+ require . def || ( require . def = function ( deps , factory ) { module . exports = factory ( ) ; } ) ;
17
+ require . def ( [ ] , function ( ) {
16
18
17
19
// setup primitive classes to be JSON Schema types
18
20
String . type = "string" ;
@@ -22,8 +24,8 @@ exports.Integer = {type:"integer"};
22
24
Object . type = "object" ;
23
25
Array . type = "array" ;
24
26
Date . type = "date" ;
25
-
26
- exports . validate = function ( /*Any*/ instance , /*Object*/ schema ) {
27
+ var exports = validate ;
28
+ exports . validate = function validate ( /*Any*/ instance , /*Object*/ schema ) {
27
29
// Summary:
28
30
// To use the validator call JSONSchema.validate with an instance object and an optional schema object.
29
31
// If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
@@ -237,50 +239,6 @@ exports.mustBeValid = function(result){
237
239
throw new TypeError ( result . errors . map ( function ( error ) { return "for property " + error . property + ': ' + error . message ; } ) . join ( ", \n" ) ) ;
238
240
}
239
241
}
240
- /* will add this later
241
- newFromSchema : function() {
242
- }
243
- */
244
242
245
- exports . cacheLinks = true ;
246
- exports . getLink = function ( relation , instance , schema ) {
247
- // gets the URI of the link for the given relation based on the instance and schema
248
- // for example:
249
- // getLink(
250
- // "brother",
251
- // {"brother_id":33},
252
- // {links:[{rel:"brother", href:"Brother/{brother_id}" }] }) ->
253
- // "Brother/33"
254
- var links = schema . __linkTemplates ;
255
- if ( ! links ) {
256
- links = { } ;
257
- var schemaLinks = schema . links ;
258
- if ( schemaLinks && schemaLinks instanceof Array ) {
259
- schemaLinks . forEach ( function ( link ) {
260
- /* // TODO: allow for multiple same-name relations
261
- if(links[link.rel]){
262
- if(!(links[link.rel] instanceof Array)){
263
- links[link.rel] = [links[link.rel]];
264
- }
265
- }*/
266
- links [ link . rel ] = link . href ;
267
- } ) ;
268
- }
269
- if ( exports . cacheLinks ) {
270
- schema . __linkTemplates = links ;
271
- }
272
- }
273
- var linkTemplate = links [ relation ] ;
274
- return linkTemplate && exports . substitute ( linkTemplate , instance ) ;
275
- } ;
276
-
277
- exports . substitute = function ( linkTemplate , instance ) {
278
- return linkTemplate . replace ( / \{ ( [ ^ \} ] * ) \} / g, function ( t , property ) {
279
- var value = instance [ decodeURIComponent ( property ) ] ;
280
- if ( value instanceof Array ) {
281
- // the value is an array, it should produce a URI like /Table/(4,5,8) and store.get() should handle that as an array of values
282
- return '(' + value . join ( ',' ) + ')' ;
283
- }
284
- return value ;
285
- } ) ;
286
- } ;
243
+ return exports ;
244
+ } ) ;
0 commit comments