From aef4b474096d0f2041adde75160872d763d69270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Thu, 2 Jul 2020 02:03:42 +0300 Subject: [PATCH] Add $id values to remote schemas This way, index.js is not required to understand what is going on, and e.g. a static *.schema.json file analyzer can pick up those schemas and link them together. --- index.js | 16 ++++++++-------- remotes/folder/folderInteger.json | 1 + remotes/integer.json | 1 + remotes/name-defs.json | 1 + remotes/name.json | 1 + remotes/subSchemas-defs.json | 1 + remotes/subSchemas.json | 1 + 7 files changed, 14 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 16dc3a5b..8a77fee8 100644 --- a/index.js +++ b/index.js @@ -3,13 +3,13 @@ const Ajv = require('ajv'); const jsonSchemaTest = require('json-schema-test'); -const refs = { - 'http://localhost:1234/integer.json': require('./remotes/integer.json'), - 'http://localhost:1234/subSchemas.json': require('./remotes/subSchemas.json'), - 'http://localhost:1234/folder/folderInteger.json': require('./remotes/folder/folderInteger.json'), - 'http://localhost:1234/name.json': require('./remotes/name.json'), - 'http://localhost:1234/name-defs.json': require('./remotes/name-defs.json') -}; +const refs = [ + require('./remotes/integer.json'), + require('./remotes/subSchemas.json'), + require('./remotes/folder/folderInteger.json'), + require('./remotes/name.json'), + require('./remotes/name-defs.json') +]; const SKIP = { 4: ['optional/zeroTerminatedFloats'], @@ -32,7 +32,7 @@ const SKIP = { ajv.addMetaSchema(require(`ajv/lib/refs/json-schema-draft-0${draft}.json`)); ajv._opts.defaultMeta = `http://json-schema.org/draft-0${draft}/schema#`; } - for (const uri in refs) ajv.addSchema(refs[uri], uri); + for (const ref of refs) ajv.addSchema(ref, ref.$id); jsonSchemaTest(ajv, { description: `Test suite draft-0${draft}`, diff --git a/remotes/folder/folderInteger.json b/remotes/folder/folderInteger.json index 8b50ea30..d4ff9ded 100644 --- a/remotes/folder/folderInteger.json +++ b/remotes/folder/folderInteger.json @@ -1,3 +1,4 @@ { + "$id": "http://localhost:1234/folder/folderInteger.json", "type": "integer" } diff --git a/remotes/integer.json b/remotes/integer.json index 8b50ea30..771b18e9 100644 --- a/remotes/integer.json +++ b/remotes/integer.json @@ -1,3 +1,4 @@ { + "$id": "http://localhost:1234/integer.json", "type": "integer" } diff --git a/remotes/name-defs.json b/remotes/name-defs.json index 1dab4a43..dc4a77be 100644 --- a/remotes/name-defs.json +++ b/remotes/name-defs.json @@ -1,4 +1,5 @@ { + "$id": "http://localhost:1234/name-defs.json", "$defs": { "orNull": { "anyOf": [ diff --git a/remotes/name.json b/remotes/name.json index fceacb80..41879857 100644 --- a/remotes/name.json +++ b/remotes/name.json @@ -1,4 +1,5 @@ { + "$id": "http://localhost:1234/name.json", "definitions": { "orNull": { "anyOf": [ diff --git a/remotes/subSchemas-defs.json b/remotes/subSchemas-defs.json index 50b7b6dc..07caba74 100644 --- a/remotes/subSchemas-defs.json +++ b/remotes/subSchemas-defs.json @@ -1,4 +1,5 @@ { + "$id": "http://localhost:1234/subSchemas-defs.json", "$defs": { "integer": { "type": "integer" diff --git a/remotes/subSchemas.json b/remotes/subSchemas.json index 9f8030bc..6b1e3c8c 100644 --- a/remotes/subSchemas.json +++ b/remotes/subSchemas.json @@ -1,4 +1,5 @@ { + "$id": "http://localhost:1234/subSchemas.json", "integer": { "type": "integer" },