ajv.test.js 737 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const AJV = require('ajv')
  2. const fastUri = require('../')
  3. const ajv = new AJV({
  4. uriResolver: fastUri // comment this line to see it works with uri-js
  5. })
  6. const test = require('tape')
  7. test('ajv', t => {
  8. t.plan(1)
  9. const schema = {
  10. $ref: '#/definitions/Record%3Cstring%2CPerson%3E',
  11. definitions: {
  12. Person: {
  13. type: 'object',
  14. properties: {
  15. firstName: {
  16. type: 'string'
  17. }
  18. }
  19. },
  20. 'Record<string,Person>': {
  21. type: 'object',
  22. additionalProperties: {
  23. $ref: '#/definitions/Person'
  24. }
  25. }
  26. }
  27. }
  28. const data = {
  29. joe: {
  30. firstName: 'Joe'
  31. }
  32. }
  33. const validate = ajv.compile(schema)
  34. t.ok(validate(data))
  35. })