Giter Site home page Giter Site logo

schema.js's People

Contributors

akidee avatar alexgorbatchev avatar jessejlt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

schema.js's Issues

Howto validate MongoDB instances?

Hi!

MongoDB as primary keys uses _id properties. When non-strict validating such instances _id just gets deleted. How do I specify the default primary key name? Or should I specify it explicitly in every type: 'object' schema?

TIA,
--Vladimir

typeof

Hi!

I'm sure you're aware of JS quirks in type detection, and e.g. typeof (new Number(4)) === 'object'. This can completely break coercion logic. I'd suggest to use robust _.isXXX() to determine the types of the instances, given you already required _ as dependency.

Best regards,
--Vladimir++

"additionalProperties: false" still allows for additional properties

Schema:

Schema.create({
description:"API schema",
type:"object",
fallbacks: Schema.STRICT_FALLBACKS,
properties:{
        data: {type: "object",
               additionalProperties: false,
               required: true,
               properties: { entry_title: {type: "string", required: true},
                             entry_body:  {type: "string", required: true},
                             blog_id:  {type: "integer", required: true},
                           },

              }
}
});

This validates the following JSON:

{data: {entry_title: "Title", entry_body: "Body", blog_id: "245232", zomg: "wtf"}}

Is this an issue or am I missing something?

Update to work with a more recent underscore.js

Presently, I can't require('schema') and require('underscore') for npm installed versions of those libraries as schema.js references an older version of underscore (which it installs automatically, as a dependency) and there is some kind of naming conflict.

My node.js script throws the following error if I require both (but I can require either apart from the other):

exception: ReferenceError: _ is not defined
stack: ReferenceError: _ is not defined

Should we expect an update soon that will make it possible to use schema.js alongside the latest release of underscore?

Thanks for a great library, schema is beyond useful. :-)

$ref

Hi!

Suppose I have:

`
model.A = {properties:{
id: String, title: String
}}

model.B = {properties:{
id: String,
a: ???
}}
`

What should I substitute for definition of B.properties.a to make it a validating reference to an instance of model.A? Which value should I then feed to B.properties.a for schema to be valid?

TIA,
--Vladimir

TypeError when using minLength

When using minLength i allways get this error: TypeError: Cannot read property 'minLength' of undefined

var register_schema = schemaEnv.Schema.create({
    type: 'object',
    properties: {
        email: {
            type: 'string',
            minLength: 6,
            maxLength: 200,
            optional: false
        }
}

var v = register_schema.validate({email:'[email protected]'});

TypeError: Cannot read property 'minLength' of undefined
at /usr/local/lib/node_modules/schema/i18n/default.js:23:57
at new (/usr/local/lib/node_modules/schema/lib/validation.js:69:44)
at [object Object]. (/usr/local/lib/node_modules/schema/lib/validation.js:205:14)
at [object Object].callPlugin (/usr/local/lib/node_modules/schema/lib/validation.js:186:18)
at [object Object].minLength (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:453:12)
at [object Object].type (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:148:22)
at [object Object].start (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:37:20)
at [object Object].properties (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:276:18)
at [object Object].type (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:174:22)
at [object Object].start (/usr/local/lib/node_modules/schema/lib/draft-02/validation.js:37:20)

"Schema is not defined" after update

Code:

var env = require('schema')('envIdentifier', {});
var schema1 = env.Schema.create({
    ...
});

throws

ReferenceError: Schema is not defined

at that second line.

Started after latest update.

$ref and defaults

How can I assign a default to a $ref-erencing property:

lang: {$ref: 'Language.properties.id', default: 'ru'} doesn't work. Assigning 'default' attribute to id property of Language schema works, but by sense is not right, for I want to overwrite defaults in referencing properties.

Any clue?

TIA,
--Vladimir

package.json

Please, create the subj, or schema.js dependencies are not solved by module loaders (nodules, npm)

TIA,
--Vladimir

optional

Hi!

{a: ''} fails to validate tolerantly against a: {type: 'number', optional: true}. I'd think a should be just ignored, as it is optional, when a validation fails, no?

--dvv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.