nfroidure / whook

Build strong and efficient REST web services.
https://slides.com/nfroidure/introducing-whook
MIT License
31 stars 7 forks source link

Support recursive schema #91

Closed nfroidure closed 3 years ago

nfroidure commented 3 years ago

Looks like recursive schemas are leading to errors, here are a few things to check :

nfroidure commented 3 years ago

For AJV, this works:

const AJV = require('ajv');

const schema = {
  type: 'object',
  required: ['id', 'childs'],
  additionalProperties: false,
  properties: {
    id: { type: 'string' },
    childs: {
      type: 'array',
      items: { $ref: '#' },
    },
  },
};

var ajv = new AJV();

const valid = ajv.validate(schema, {
  id: '1',
  childs: [
    {
      id: 'id',
      childs: [],
    },
  ],
});
if (!valid) console.log(ajv.errors);