Validate JSON schema with Ajv
— javascript, typescript, JSON — 1 min read
WIP
anyOf
outcome
becomes required
when the incoming @type
is either Admin or Safeguarding
export const updateNoteSchema = { type: 'object', properties: { '@type': { type: 'string', enum: [NoteType.Admin, NoteType.Safeguarding], }, action: { type: 'object', properties: { description: { type: 'string', minLength: 1 }, reviewedAt: { type: 'string', minLengh: 1 }, reviewedBy: { type: 'object', properties: { '@type': { type: 'string', enum: ['user'] }, '@id': { type: 'string', format: 'uuid' }, }, required: ['@type', '@id'], }, }, dependentSchemas: { reasonForReview: { required: ['@type'] }, }, required: ['description', 'reviewedAt', 'reviewedBy'], }, }, anyOf: [ { properties: { '@type': { enum: [NoteType.Admin, NoteType.Safeguarding] }, }, required: ['outcome'], }, ],};