ajv.test.js 752 B

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