Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate hang #56

Open
shachr opened this issue Jun 13, 2015 · 1 comment
Open

validate hang #56

shachr opened this issue Jun 13, 2015 · 1 comment

Comments

@shachr
Copy link

shachr commented Jun 13, 2015

given the following object and schema the validate function hang:

object:

{
    provider: { name: "1" }
}

schema:

{
        id:"/api/accounts/register",
        type: "object",
        oneOf: [ { $ref:"#/definitions/social" }, { $ref:"#/definitions/site" } ],


        definitions: {
            social: {
                additionalProperties: false,
                type: 'object',
                properties: {
                    provider: { enum: [ "facebook" ], required:true }
                }
            },
            site: {
                additionalProperties: false,
                type: 'object',
                properties: {
                    username: { type: "string", required:true },
                    password: { type: "string", required:true },

                    firstname: { type: "string" },
                    lastname: { type: "string" },
                    email: { type: "string" },
                    isSubscribed: { type: "boolean" }
                }
            }
        }
    }
@natesilva
Copy link
Owner

In JSON Schema v4, the required attribute must be an array, and it is a property of the object definition. This was one of the main things that changed from v3. Try this:

var schema = {
    id:"/api/accounts/register",
    type: "object",
    oneOf: [ { $ref:"#/definitions/social" }, { $ref:"#/definitions/site" } ],


    definitions: {
        social: {
            additionalProperties: false,
            type: 'object',
            required: ['provider'],
            properties: {
                provider: { 'enum': [ "facebook" ] }
            }
        },
        site: {
            additionalProperties: false,
            type: 'object',
            required: ['username', 'password'],
            properties: {
                username: { type: "string" },
                password: { type: "string" },

                firstname: { type: "string" },
                lastname: { type: "string" },
                email: { type: "string" },
                isSubscribed: { type: "boolean" }
            }
        }
    }
};

I agree, though, the fact that this hangs is bad and I will take a look preventing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants