Skip to content

Optional object validation #109

@iparrabb

Description

@iparrabb

Is possible that the s3Object only will be required when s3Object key exists?

const schema = {
  name: {
    type: String,
    required: true
  },
  s3Object: {
    name: {
      type: String
    },
    data: {
      type: String
    }
  }
}

The following example pass validation, but I need that fails because s3Object is defined
but it doesn't have the name and data properties:

const obj = {
  name: "test",
  s3Object: {
    
  }
}

Only can pass the validation the next examples:

const obj1 = {
  name: "test"
}
const obj2 = {
  name: "test",
  s3Object: {
    name: "test",
    data: "dopafawe"
  }
}

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions