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

Optional nested schema #113

Open
sidvorak opened this issue Mar 31, 2020 · 0 comments
Open

Optional nested schema #113

sidvorak opened this issue Mar 31, 2020 · 0 comments

Comments

@sidvorak
Copy link

I'm having an issue when attempting to use a nested schema. For instance:

const Camera = new Schema({
    model: {
        type: string,
        required: true,
    }
};

const Room = new Schema({
    name: {
        type: string,
        required: true,
    }
    camera: {
        type: Camera,
        required: false
    }
};

const roomObj = {
    name: "My room",
    camera: {
        model: "abc123"
    }
};

const errors = Room.validate(roomObj);
// ValidationError: camera must be of type [object Object].

If I define the room schema like:

const Room = new Schema({
    name: {
        type: string,
        required: true,
    }
    camera: Camera
};

const roomObj = {
    name: "My room",
    camera: {
        model: "abc123"
    }
};

It works as long as I pass the nested camera object with the required properties, but I get validation errors if the nested camera object is not including in the room object.

Is there a way to have an optional nested schema?

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

1 participant