Created
January 30, 2018 08:42
-
-
Save hipstersmoothie/21906ec9d2ca9525b066224d77ab8eff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$id": "asset_action", | |
"title": "Action", | |
"properties": { | |
"type": { | |
"const": "action" | |
}, | |
"label": { | |
"$ref": "text_assets" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$id": "def", | |
"definitions": { | |
"view_gateway": { | |
"title": "Gateway", | |
"properties": { | |
"gatewayActions": { | |
"type": "object", | |
"properties": { | |
"affirmativeAction": { | |
"$ref": "#/definitions/actions" | |
}, | |
"negativeAction": { | |
"$ref": "#/definitions/actions" | |
}, | |
"prevAction": { | |
"$ref": "#/definitions/actions" | |
} | |
} | |
} | |
} | |
}, | |
"actions": { | |
"title": "Action Asset", | |
"type": "object", | |
"properties": { | |
"asset": { | |
"$ref": "asset_action" | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var _ = require('lodash'); | |
var $RefParser = require("json-schema-ref-parser"); | |
var fs = require('fs'); | |
var mySchema = require('./frf_schema.json'); | |
var definitions = require('./definitions.json'); | |
var assets = require('./assets/index'); | |
const allAssets = [...assets, definitions]; | |
const findSchema = (file) => { | |
var id = _.last(file.url.split('/')); | |
return _.find(allAssets, function (asset) { | |
return asset.$id === id; | |
}); | |
} | |
const myResolver = { | |
order: 1, | |
canRead: findSchema, | |
read: findSchema | |
}; | |
const fileName = "merged-schema.json"; | |
$RefParser.bundle(mySchema, { resolve: { mongo: myResolver } }) | |
.then((schema) => ( | |
fs.writeFile(fileName, JSON.stringify(schema)) | |
)) | |
.then(() => ( | |
// eslint-disable-next-line no-console | |
console.log("Merged Schema saved to:", fileName) | |
)) | |
.catch((err) => ( | |
// eslint-disable-next-line no-console | |
console.error(err) | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"type": "object", | |
"$id": "root", | |
"properties": { | |
"views": { | |
"type": "array", | |
"items": { | |
"title": "Gateway", | |
"properties": { | |
"gatewayActions": { | |
"type": "object", | |
"properties": { | |
"affirmativeAction": { | |
"$ref": "#/properties/views/items/properties/gatewayActions/properties/prevAction" | |
}, | |
"negativeAction": { | |
"$ref": "#/properties/views/items/properties/gatewayActions/properties/prevAction" | |
}, | |
"prevAction": { | |
"title": "Action Asset", | |
"type": "object", | |
"properties": { | |
"asset": { | |
"$id": "asset_action", | |
"title": "Action", | |
"properties": { | |
"type": { | |
"const": "action" | |
}, | |
"label": { | |
"$id": "text_assets", | |
"title": "Text Assets", | |
"description": "A text asset or grouping of text assets.", | |
"oneOf": [ | |
{ | |
"$ref": "#/properties/views/items/properties/gatewayActions/properties/affirmativeAction/properties/asset/properties/label/definitions/switch" | |
}, | |
{ | |
"$ref": "#/properties/views/items/properties/gatewayActions/properties/affirmativeAction/properties/asset/properties/label/definitions/switch_wrapper" | |
} | |
], | |
"definitions": { | |
"switch_wrapper": { | |
"type": "object", | |
"properties": { | |
"staticSwitch": { | |
"$ref": "#/properties/views/items/properties/gatewayActions/properties/affirmativeAction/properties/asset/properties/label/definitions/switch" | |
} | |
} | |
}, | |
"asset": { | |
"type": "object", | |
"$id": "asset_text", | |
"title": "Text", | |
"description": "The text asset is the most basic type. Text assets are used to convey one or part of a thought to a user. They can be used within any other asset, but cannot contain other assets within.", | |
"required": [ | |
"value" | |
], | |
"properties": { | |
"type": { | |
"const": "text" | |
} | |
} | |
}, | |
"switch": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"asset": { | |
"$ref": "#/properties/views/items/properties/gatewayActions/properties/affirmativeAction/properties/asset/properties/label/definitions/asset" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "http://json-schema.org/draft-07/schema#", | |
"type": "object", | |
"$id": "root", | |
"properties": { | |
"views": { | |
"type": "array", | |
"items": { | |
"$ref": "def#/definitions/view_gateway" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$id": "text_assets", | |
"title": "Text Assets", | |
"description": "A text asset or grouping of text assets.", | |
"oneOf": [ | |
{ | |
"$ref": "#/definitions/switch" | |
}, | |
{ | |
"$ref": "#/definitions/switch_wrapper" | |
} | |
], | |
"definitions": { | |
"switch_wrapper": { | |
"type": "object", | |
"properties": { | |
"staticSwitch": { | |
"$ref": "#/definitions/switch" | |
} | |
} | |
}, | |
"asset": { | |
"type": "object", | |
"$ref": "asset_text" | |
}, | |
"switch": { | |
"type": "array", | |
"items": { | |
"type": "object", | |
"properties": { | |
"asset": { | |
"$ref": "#/definitions/asset" | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment