From aed3bde7ac53fc5fdaa98cc8b67562d1e7623390 Mon Sep 17 00:00:00 2001 From: Jakob Olsson <Jakob Olsson> Date: Fri, 13 Dec 2019 11:14:04 +0100 Subject: [PATCH] add support for a folder containing defitinition files --- cli.js | 5 ++++- lib/schema.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cli.js b/cli.js index d93e807..00c1084 100755 --- a/cli.js +++ b/cli.js @@ -64,7 +64,10 @@ const { argv } = Optimist .describe('p', 'A comma separated list with custom properties which should be also in the description of an element.') .alias('h', 'header') .describe('h', 'if the value is false the header will be skipped') - .default('h', true); + .default('h', true) + .alias('u', 'definitions') + .describe('u', 'folder containing definition file(s)') + .default('u', './'); const docs = _.fromPairs( _.toPairs(argv) diff --git a/lib/schema.js b/lib/schema.js index 2869a94..d00fda4 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -34,6 +34,7 @@ const absUrlRegex = new RegExp('^(?:[a-z]+:)?//', 'i'); let smap; // TODO remove global let sPath; +let definitionsDir; const wmap = {}; function get$refType(refValue) { let startpart = ''; @@ -122,6 +123,22 @@ const resolve$ref = Promise.method((val, base$id) => { return processISchema(ischema, refArr.startpart); } } + const $ref = val.$ref.split('#'); + if ($ref[0].length) { + const uri = $ref[0]; + const raw = fs.readFileSync(definitionsDir + uri.split('/').pop(-1)); + const definitions = JSON.parse(raw); + console.log('defitinitons.$id', definitions.$id, 'uri', uri); + if (definitions.$id !== uri) return undefined; + + const keys = $ref[1].split('/'); + let ref = definitions; + keys.forEach((key) => { + if (key.length) ref = ref[key]; + }); + return ref; + } + return undefined; }); const processFurther = Promise.method((val, key, $id) => { @@ -438,6 +455,7 @@ Schema.setSchemaPathMap = function (schemaMap) { */ Schema.process = (schemaMap, schemaPath, docDir, schemaDir, metaElements, readme, docs, consoleArgs) => { + definitionsDir = consoleArgs.u; smap = schemaMap; const keys = Object.keys(schemaMap); return Promise.mapSeries(keys, (schemaKey) => { @@ -461,6 +479,7 @@ Schema.process = (schemaMap, schemaPath, docDir, schemaDir, mSchema.metaElements = metaElements; if (mSchema.properties) { Object.keys(mSchema.properties).forEach((method) => { + if (!mSchema.properties[method].properties) return; const { input } = mSchema.properties[method].properties; const { output } = mSchema.properties[method].properties; if (input) { -- GitLab