Skip to content
Youngho Chaa cha cha
TwitterHomepage

Validate JSON schema with Ajv

javascript, typescript, JSON1 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'],
},
],
};
© 2024 by Youngho Chaa cha cha. All rights reserved.
Theme by LekoArts