objection.js icon indicating copy to clipboard operation
objection.js copied to clipboard

patch validator logic does not deeply remove "required" key from jsonSchema

Open bompus opened this issue 6 years ago • 0 comments

I ran into an issue when a jsonSchema contains nested objects with required keys. Currently, it appears that only the top-level required key is removed when using patch.

static get jsonSchema() {
    return {
      type: 'object',
      required: ['id'],
      properties: {
        id: { type: 'integer' },
        meta: {
          type: 'object',
          required: ['id2'],
          properties: {
            id2: { type: 'integer' },
            foo: { type: 'string' }
        }
   }
};

Because of this, when I try to patch ["meta:foo"] = "bar", I get a validation error because id2 isn't present. I'm submitting a PR for review in a few minutes.

bompus avatar Jan 28 '20 05:01 bompus