├── .eslintrc.json ├── .github └── FUNDING.yml ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── lib ├── common.js ├── core.js ├── draft-04.js ├── draft-06.js ├── draft-07.js ├── draft-2019-09.js ├── draft-2020-12.js ├── fixtures │ ├── main.schema.json │ ├── mixed-schemes.schema.json │ └── string.schema.json ├── index.d.ts ├── index.js ├── index.mjs ├── keywords.js ├── test-runner.spec.ts └── tests │ ├── advanced.json │ ├── basic.json │ ├── external-schemas.json │ ├── file.json │ ├── flat-bundle.json │ ├── full-bundle.json │ └── keywords.json ├── package.json ├── rollup.config.js └── tsconfig.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "env": { 4 | "es6": true, 5 | "node": true, 6 | "browser": "true" 7 | }, 8 | "parserOptions": { 9 | "ecmaVersion": 2018 10 | }, 11 | "extends": [ 12 | "eslint:recommended" 13 | ], 14 | "plugins": ["import"], 15 | "rules": { 16 | "array-bracket-spacing": ["error", "never"], 17 | "block-spacing": ["error", "always"], 18 | "brace-style": ["error", "1tbs"], 19 | "comma-dangle": ["error", "never"], 20 | "comma-spacing": "error", 21 | "default-param-last": "error", 22 | "func-call-spacing": "error", 23 | "import/no-unresolved": ["error", { "commonjs": true }], 24 | "import/extensions": ["error", "always", { "js": "never" }], 25 | "import/newline-after-import": ["error", { "count": 2 }], 26 | "indent": ["error", 2, { "ignoreComments": true }], 27 | "keyword-spacing": "error", 28 | "linebreak-style": ["error", "unix"], 29 | "no-loss-of-precision": "error", 30 | "no-prototype-builtins": ["off"], 31 | "no-return-await": "error", 32 | "no-trailing-spaces": "error", 33 | "no-tabs": "error", 34 | "no-throw-literal": "error", 35 | "no-unused-expressions": "error", 36 | "no-unused-vars": ["error", { "argsIgnorePattern": "_.*" }], 37 | "object-curly-spacing": ["error", "always"], 38 | "quotes": ["error", "double", { "allowTemplateLiterals": true }], 39 | "semi": ["error", "always"], 40 | "space-before-function-paren": ["error", { "named": "never" }], 41 | "space-infix-ops": "error" 42 | }, 43 | "settings": { 44 | "import/resolver": "node" 45 | }, 46 | "overrides": [ 47 | { 48 | "files": ["**/*.ts"], 49 | "extends": [ 50 | "eslint:recommended", 51 | "plugin:@typescript-eslint/eslint-recommended", 52 | "plugin:@typescript-eslint/recommended", 53 | "plugin:@typescript-eslint/recommended-requiring-type-checking" 54 | ], 55 | "parserOptions": { 56 | "project": "./tsconfig.json" 57 | }, 58 | "settings": { 59 | "import/resolver": "typescript" 60 | }, 61 | "rules": { 62 | "no-prototype-builtins": ["off"], 63 | "import/extensions": ["error", "always", { "ts": "never" }], 64 | "@typescript-eslint/array-type": "error", 65 | "brace-style": "off", 66 | "@typescript-eslint/brace-style": ["error", "1tbs"], 67 | "comma-dangle": "off", 68 | "@typescript-eslint/comma-dangle": ["error", "never"], 69 | "comma-spacing": "off", 70 | "@typescript-eslint/comma-spacing": "error", 71 | "@typescript-eslint/consistent-type-assertions": "error", 72 | "@typescript-eslint/consistent-type-definitions": ["error", "type"], 73 | "@typescript-eslint/consistent-type-imports": "error", 74 | "default-param-last": "off", 75 | "@typescript-eslint/default-param-last": "error", 76 | "func-call-spacing": "off", 77 | "@typescript-eslint/func-call-spacing": "error", 78 | "indent": "off", 79 | "@typescript-eslint/indent": ["error", 2, { "ignoreComments": true }], 80 | "keyword-spacing": "off", 81 | "@typescript-eslint/keyword-spacing": "error", 82 | "@typescript-eslint/method-signature-style": "error", 83 | "@typescript-eslint/no-base-to-string": "error", 84 | "@typescript-eslint/no-confusing-void-expression": "error", 85 | "@typescript-eslint/no-implicit-any-catch": "error", 86 | "no-loss-of-precision": "off", 87 | "@typescript-eslint/no-loss-of-precision": "error", 88 | "@typescript-eslint/no-meaningless-void-operator": "error", 89 | "no-throw-literal": "off", 90 | "@typescript-eslint/no-throw-literal": "error", 91 | "@typescript-eslint/no-unnecessary-boolean-literal-compare": "error", 92 | "@typescript-eslint/no-unnecessary-condition": "error", 93 | "@typescript-eslint/no-unnecessary-qualifier": "error", 94 | "@typescript-eslint/no-unnecessary-type-arguments": "error", 95 | "@typescript-eslint/no-unnecessary-type-constraint": "error", 96 | "@typescript-eslint/no-unsafe-argument": "warn", 97 | "@typescript-eslint/no-unsafe-assignment": "warn", 98 | "@typescript-eslint/no-unsafe-call": "warn", 99 | "@typescript-eslint/no-unsafe-member-access": "warn", 100 | "@typescript-eslint/no-unsafe-return": "warn", 101 | "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "_.*" }], 102 | "no-unused-expressions": "off", 103 | "@typescript-eslint/no-unused-expressions": "error", 104 | "@typescript-eslint/non-nullable-type-assertion-style": "error", 105 | "object-curly-spacing": "off", 106 | "@typescript-eslint/object-curly-spacing": ["error", "always"], 107 | "@typescript-eslint/prefer-for-of": "error", 108 | "@typescript-eslint/prefer-reduce-type-parameter": "error", 109 | "quotes": "off", 110 | "@typescript-eslint/quotes": ["error", "double", { "allowTemplateLiterals": true }], 111 | "no-return-await": "off", 112 | "@typescript-eslint/require-await": ["off"], 113 | "@typescript-eslint/return-await": "error", 114 | "semi": "off", 115 | "@typescript-eslint/semi": ["error", "always"], 116 | "space-before-function-paren": "off", 117 | "@typescript-eslint/space-before-function-paren": ["error", { "named": "never" }], 118 | "space-infix-ops": "off", 119 | "@typescript-eslint/space-infix-ops": "error", 120 | "@typescript-eslint/type-annotation-spacing": "error" 121 | } 122 | } 123 | ] 124 | } 125 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [jdesrosiers] 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ 3 | package-lock.json 4 | worksheet.js 5 | worksheet.ts 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .github/ 2 | rollup.config.js 3 | .eslintrc.json 4 | **/*.spec.ts 5 | lib/fixtures/ 6 | lib/tests/ 7 | tsconfig.json 8 | worksheet.js 9 | worksheet.ts 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jason Desrosiers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # THIS FUNCTIONALITY HAS MOVED TO [@hyperjump/json-schema](https://github.com/hyperjump-io/json-schema#bundling) 2 | 3 | # Hyperjump - JSON Schema Bundle 4 | 5 | JSON Schema Bundle (JSB) is an implementation of the official JSON Schema 6 | bundling process introduced in the Draft 2020-12 specification. Given a schema 7 | with external references, any external schemas will be embedded in the schema 8 | resulting in a Compound Schema Document with all the schemas necessary to 9 | evaluate the given schema. 10 | 11 | The bundling process allows schemas to be embedded without needing to modify any 12 | references which means you get the same output details whether you validate the 13 | bundle or the original unbundled schemas. 14 | 15 | JSON Schema Bundle (JSB) is built on [JSON Schema Core](https://github.com/hyperjump-io/json-schema-core). 16 | 17 | * Supported JSON Schema Dialects 18 | * draft-04 | draft-06 | draft-07 | Draft 2019-09 | Draft 2020-12 19 | * Support for custom dialects can be configured 20 | * Schemas can reference other schemas using a different draft 21 | * Load schemas from filesystem (file://), network (http(s)://), or JavaScript 22 | 23 | ## Install 24 | JSB includes support for node.js JavaScript (CommonJS and ES Modules), 25 | TypeScript, and browsers. 26 | 27 | ### Node.js 28 | ```bash 29 | npm install @hyperjump/json-schema-bundle 30 | ``` 31 | 32 | ### Browser 33 | When in a browser context, JSB is designed to use the browser's `fetch` 34 | implementation instead of a node.js fetch clone. The Webpack bundler does this 35 | properly without any extra configuration, but if you are using the Rollup 36 | bundler you will need to include the `browser: true` option in your Rollup 37 | configuration. 38 | 39 | ```javascript 40 | plugins: [ 41 | resolve({ 42 | browser: true 43 | }), 44 | commonjs() 45 | ] 46 | ``` 47 | 48 | ### Versioning 49 | This project is in beta and there may be breaking changes at any time. When it's 50 | stable enough, I'll publish v1.0.0 and follow semantic versioning from there on 51 | out. 52 | 53 | ## Usage 54 | ```javascript 55 | const Bundler = require("@hyperjump/json-schema-bundle"); 56 | 57 | 58 | // Optionally load schema manually 59 | Bundler.add({ 60 | "$id": "https://json-schema.hyperjump.io/schemas/string", 61 | "$schema": "https://json-schema.org/draft/2020-12/schema", 62 | 63 | "type": "string" 64 | }); 65 | 66 | // Get the initial schema to pass to the bundler 67 | const main = await Bundler.get(`file://${__dirname}/schemas/main.schema.json`); 68 | 69 | // The bundler will fetch from the file system, network, or internal schemas as 70 | // needed to build to bundle. 71 | const bundle = await Bundler.bundle(main); 72 | ``` 73 | 74 | ## TypeScript 75 | Although the package is written in JavaScript, type definitions are included for 76 | TypeScript support. The following example shows the types you might want to 77 | know. 78 | 79 | ```typescript 80 | import Bundler from "@hyperjump/json-schema-bundle"; 81 | import type { SchemaDocument, Draft202012Schema, InvalidSchemaError } from "@hyperjump/json-schema-bundle"; 82 | 83 | 84 | (async function () { 85 | const schemaJson: Draft202012Schema = { 86 | "$id": "https://json-schema.hyperjump.io/schemas/string", 87 | "$schema": "https://json-schema.org/draft/2020-12/schema", 88 | 89 | "type": "string" 90 | }; 91 | Bundler.add(schemaJson); 92 | 93 | try { 94 | const main: SchemaDocument = await Bundler.get(`file://${__dirname}/schemas/main.schema.json`); 95 | const bundle: Draft202012Schema = await Bundler.bundle(main); 96 | console.log(JSON.stringify(bundle, null, " ")); 97 | } catch (error: unknown) { 98 | if (error instanceof InvalidSchemaError) { 99 | console.log(error.output); 100 | } else { 101 | console.log(error); 102 | } 103 | } 104 | }()); 105 | ``` 106 | 107 | ## API 108 | * **add**: (schema: object, url?: URI, schemaVersion?: string) => SDoc 109 | 110 | Load a schema. See [JSC - $id](https://github.com/hyperjump-io/json-schema-core#id) 111 | and [JSC - $schema](https://github.com/hyperjump-io/json-schema-core#schema-1) 112 | for more information. 113 | * **get**: (url: URI, contextDoc?: SDoc, recursive: boolean = false) => Promise\ 114 | 115 | Fetch a schema. Schemas can come from an HTTP request, a file, or a schema 116 | that was added with `add`. 117 | * **bundle**: (schema: SDoc, options: Options) => Promise\ 118 | 119 | Create a bundled schema starting with the given schema. External schemas 120 | will be fetched from the filesystem, the network, or internally as needed. 121 | 122 | Options: 123 | * alwaysIncludeDialect: boolean (default: false) -- Include dialect even 124 | when it isn't strictly needed 125 | * bundleMode: "flat" | "full" (default: "flat") -- When bundling schemas 126 | that already contain bundled schemas, "flat" mode with remove nested 127 | embedded schemas and put them all in the top level `$defs`. When using 128 | "full" mode, it will keep the already embedded schemas around, which will 129 | result in some embedded schema duplication. 130 | * definitionNamingStrategy: "uri" | "uuid" (default: "uri") -- By default 131 | the name used in definitions for embedded schemas will match the 132 | identifier of the embedded schema. This naming is unlikely to collide 133 | with actual definitions, but if you want to be sure, you can use the 134 | "uuid" strategy instead to be sure you get a unique name. 135 | * externalSchemas: string[] (default: []) -- A list of schemas URIs that 136 | are available externally and should not be included in the bundle. 137 | * **setMetaOutputFormat**: (outputFormat: OutputFormat = DETAILED) => undefined 138 | 139 | Set the output format for meta-validation. Meta-validation output is only 140 | returned if meta-validation results in an error. 141 | * **setShouldMetaValidate**: (isEnabled: boolean) => undefined 142 | 143 | Enable or disable meta-validation. 144 | * **OutputFormat**: [**FLAG** | **BASIC** | **DETAILED** | **VERBOSE**] 145 | 146 | See [JSC - Output](https://github.com/hyperjump-io/json-schema-core#output) 147 | for more information on output formats. 148 | 149 | ## Contributing 150 | 151 | ### Tests 152 | 153 | Run the tests 154 | 155 | ```bash 156 | npm test 157 | ``` 158 | 159 | Run the tests with a continuous test runner 160 | 161 | ```bash 162 | npm test -- --watch 163 | ``` 164 | -------------------------------------------------------------------------------- /lib/common.js: -------------------------------------------------------------------------------- 1 | const splitUri = (url) => { 2 | const indexOfHash = url.indexOf("#"); 3 | const ndx = indexOfHash === -1 ? url.length : indexOfHash; 4 | const urlReference = url.slice(0, ndx); 5 | const urlFragment = url.slice(ndx + 1); 6 | 7 | return [decodeURI(urlReference), decodeURI(urlFragment)]; 8 | }; 9 | 10 | module.exports = { splitUri }; 11 | -------------------------------------------------------------------------------- /lib/core.js: -------------------------------------------------------------------------------- 1 | const { Core } = require("@hyperjump/json-schema-core"); 2 | const { splitUri } = require("./common"); 3 | 4 | 5 | const collectExternalIds = (schemaUri, externalIds, ast, dynamicAnchors) => { 6 | const keywordId = ast[schemaUri][0]; 7 | const id = splitUri(schemaUri)[0]; 8 | Core.getKeyword(keywordId).collectExternalIds(schemaUri, externalIds, ast, { ...ast.metaData[id].dynamicAnchors, ...dynamicAnchors }); 9 | }; 10 | 11 | module.exports = { collectExternalIds }; 12 | -------------------------------------------------------------------------------- /lib/draft-04.js: -------------------------------------------------------------------------------- 1 | const JsonSchema = require("@hyperjump/json-schema"); 2 | const { Core, Schema } = require("@hyperjump/json-schema-core"); 3 | const Keywords = require("./keywords"); 4 | 5 | 6 | Schema.setConfig("http://json-schema.org/draft-04/schema", "bundlingLocation", "/definitions"); 7 | 8 | Core.defineVocabulary("http://json-schema.org/draft-04/schema", { 9 | "validate": Keywords.validate, 10 | "additionalItems": Keywords.additionalItems, 11 | "additionalProperties": Keywords.additionalProperties, 12 | "allOf": Keywords.allOf, 13 | "anyOf": Keywords.anyOf, 14 | "default": JsonSchema.Keywords.metaData, 15 | "definitions": JsonSchema.Keywords.definitions, 16 | "dependencies": Keywords.dependencies, 17 | "description": JsonSchema.Keywords.metaData, 18 | "enum": JsonSchema.Keywords.enum, 19 | "format": JsonSchema.Keywords.metaData, 20 | "items": Keywords.items, 21 | "maxItems": JsonSchema.Keywords.maxItems, 22 | "maxLength": JsonSchema.Keywords.maxLength, 23 | "maxProperties": JsonSchema.Keywords.maxProperties, 24 | "maximum": JsonSchema.Keywords.maximumExclusiveMaximum, 25 | "minItems": JsonSchema.Keywords.minItems, 26 | "minLength": JsonSchema.Keywords.minLength, 27 | "minProperties": JsonSchema.Keywords.minProperties, 28 | "minimum": JsonSchema.Keywords.minimumExclusiveMinimum, 29 | "multipleOf": JsonSchema.Keywords.multipleOf, 30 | "not": Keywords.not, 31 | "oneOf": Keywords.oneOf, 32 | "pattern": JsonSchema.Keywords.pattern, 33 | "patternProperties": Keywords.patternProperties, 34 | "properties": Keywords.properties, 35 | "required": JsonSchema.Keywords.required, 36 | "title": JsonSchema.Keywords.metaData, 37 | "type": JsonSchema.Keywords.type, 38 | "uniqueItems": JsonSchema.Keywords.uniqueItems 39 | }); 40 | -------------------------------------------------------------------------------- /lib/draft-06.js: -------------------------------------------------------------------------------- 1 | const JsonSchema = require("@hyperjump/json-schema"); 2 | const { Core, Schema } = require("@hyperjump/json-schema-core"); 3 | const Keywords = require("./keywords"); 4 | 5 | 6 | Schema.setConfig("http://json-schema.org/draft-06/schema", "bundlingLocation", "/definitions"); 7 | 8 | Core.defineVocabulary("http://json-schema.org/draft-06/schema", { 9 | "validate": Keywords.validate, 10 | "additionalItems": Keywords.additionalItems6, 11 | "additionalProperties": Keywords.additionalProperties6, 12 | "allOf": Keywords.allOf, 13 | "anyOf": Keywords.anyOf, 14 | "const": JsonSchema.Keywords.const, 15 | "contains": Keywords.contains, 16 | "default": JsonSchema.Keywords.metaData, 17 | "definitions": JsonSchema.Keywords.definitions, 18 | "dependencies": Keywords.dependencies, 19 | "description": JsonSchema.Keywords.metaData, 20 | "enum": JsonSchema.Keywords.enum, 21 | "examples": JsonSchema.Keywords.metaData, 22 | "exclusiveMaximum": JsonSchema.Keywords.exclusiveMaximum, 23 | "exclusiveMinimum": JsonSchema.Keywords.exclusiveMinimum, 24 | "format": JsonSchema.Keywords.metaData, 25 | "items": Keywords.items, 26 | "maxItems": JsonSchema.Keywords.maxItems, 27 | "maxLength": JsonSchema.Keywords.maxLength6, 28 | "maxProperties": JsonSchema.Keywords.maxProperties, 29 | "maximum": JsonSchema.Keywords.maximum, 30 | "minItems": JsonSchema.Keywords.minItems, 31 | "minLength": JsonSchema.Keywords.minLength6, 32 | "minProperties": JsonSchema.Keywords.minProperties, 33 | "minimum": JsonSchema.Keywords.minimum, 34 | "multipleOf": JsonSchema.Keywords.multipleOf, 35 | "not": Keywords.not, 36 | "oneOf": Keywords.oneOf, 37 | "pattern": JsonSchema.Keywords.pattern, 38 | "patternProperties": Keywords.patternProperties, 39 | "properties": Keywords.properties, 40 | "propertyNames": Keywords.propertyNames, 41 | "required": JsonSchema.Keywords.required, 42 | "title": JsonSchema.Keywords.metaData, 43 | "type": JsonSchema.Keywords.type, 44 | "uniqueItems": JsonSchema.Keywords.uniqueItems 45 | }); 46 | -------------------------------------------------------------------------------- /lib/draft-07.js: -------------------------------------------------------------------------------- 1 | const JsonSchema = require("@hyperjump/json-schema"); 2 | const { Core, Schema } = require("@hyperjump/json-schema-core"); 3 | const Keywords = require("./keywords"); 4 | 5 | 6 | Schema.setConfig("http://json-schema.org/draft-07/schema", "bundlingLocation", "/definitions"); 7 | 8 | Core.defineVocabulary("http://json-schema.org/draft-07/schema", { 9 | "validate": Keywords.validate, 10 | "additionalItems": Keywords.additionalItems6, 11 | "additionalProperties": Keywords.additionalProperties6, 12 | "allOf": Keywords.allOf, 13 | "anyOf": Keywords.anyOf, 14 | "const": JsonSchema.Keywords.const, 15 | "contains": Keywords.contains, 16 | "default": JsonSchema.Keywords.metaData, 17 | "definitions": JsonSchema.Keywords.definitions, 18 | "dependencies": Keywords.dependencies, 19 | "description": JsonSchema.Keywords.metaData, 20 | "enum": JsonSchema.Keywords.enum, 21 | "exclusiveMaximum": JsonSchema.Keywords.exclusiveMaximum, 22 | "exclusiveMinimum": JsonSchema.Keywords.exclusiveMinimum, 23 | "format": JsonSchema.Keywords.metaData, 24 | "if": Keywords.if, 25 | "then": Keywords.then, 26 | "else": Keywords.else, 27 | "items": Keywords.items, 28 | "maxItems": JsonSchema.Keywords.maxItems, 29 | "maxLength": JsonSchema.Keywords.maxLength6, 30 | "maxProperties": JsonSchema.Keywords.maxProperties, 31 | "maximum": JsonSchema.Keywords.maximum, 32 | "minItems": JsonSchema.Keywords.minItems, 33 | "minLength": JsonSchema.Keywords.minLength6, 34 | "minProperties": JsonSchema.Keywords.minProperties, 35 | "minimum": JsonSchema.Keywords.minimum, 36 | "multipleOf": JsonSchema.Keywords.multipleOf, 37 | "not": Keywords.not, 38 | "oneOf": Keywords.oneOf, 39 | "pattern": JsonSchema.Keywords.pattern, 40 | "patternProperties": Keywords.patternProperties, 41 | "properties": Keywords.properties, 42 | "propertyNames": Keywords.propertyNames, 43 | "readOnly": JsonSchema.Keywords.metaData, 44 | "required": JsonSchema.Keywords.required, 45 | "title": JsonSchema.Keywords.metaData, 46 | "type": JsonSchema.Keywords.type, 47 | "uniqueItems": JsonSchema.Keywords.uniqueItems, 48 | "writeOnly": JsonSchema.Keywords.metaData 49 | }); 50 | -------------------------------------------------------------------------------- /lib/draft-2019-09.js: -------------------------------------------------------------------------------- 1 | const JsonSchema = require("@hyperjump/json-schema"); 2 | const { Core, Schema } = require("@hyperjump/json-schema-core"); 3 | const Keywords = require("./keywords"); 4 | 5 | 6 | Schema.setConfig("https://json-schema.org/draft/2019-09/vocab/core", "bundlingLocation", "/$defs"); 7 | 8 | Core.defineVocabulary("https://json-schema.org/draft/2019-09/vocab/core", { 9 | "validate": Keywords.validate, 10 | "$defs": JsonSchema.Keywords.definitions, 11 | "$recursiveRef": JsonSchema.Keywords.dynamicRef, 12 | "$ref": Keywords.ref 13 | }); 14 | 15 | Core.defineVocabulary("https://json-schema.org/draft/2019-09/vocab/applicator", { 16 | "additionalItems": Keywords.additionalItems6, 17 | "additionalProperties": Keywords.additionalProperties6, 18 | "allOf": Keywords.allOf, 19 | "anyOf": Keywords.anyOf, 20 | "contains": Keywords.containsMinContainsMaxContains, 21 | "dependentSchemas": Keywords.dependentSchemas, 22 | "if": Keywords.if, 23 | "then": Keywords.then, 24 | "else": Keywords.else, 25 | "items": Keywords.items, 26 | "not": Keywords.not, 27 | "oneOf": Keywords.oneOf, 28 | "patternProperties": Keywords.patternProperties, 29 | "properties": Keywords.properties, 30 | "propertyNames": Keywords.propertyNames, 31 | "unevaluatedItems": Keywords.unevaluatedItems, 32 | "unevaluatedProperties": Keywords.unevaluatedProperties 33 | }); 34 | -------------------------------------------------------------------------------- /lib/draft-2020-12.js: -------------------------------------------------------------------------------- 1 | const JsonSchema = require("@hyperjump/json-schema"); 2 | const { Core, Schema } = require("@hyperjump/json-schema-core"); 3 | const Keywords = require("./keywords"); 4 | 5 | 6 | Schema.setConfig("https://json-schema.org/draft/2020-12/vocab/core", "bundlingLocation", "/$defs"); 7 | 8 | Core.defineVocabulary("https://json-schema.org/draft/2020-12/vocab/core", { 9 | "validate": Keywords.validate, 10 | "$defs": JsonSchema.Keywords.definitions, 11 | "$dynamicRef": JsonSchema.Keywords.dynamicRef, 12 | "$ref": Keywords.ref 13 | }); 14 | 15 | Core.defineVocabulary("https://json-schema.org/draft/2020-12/vocab/applicator", { 16 | "additionalProperties": Keywords.additionalProperties6, 17 | "allOf": Keywords.allOf, 18 | "anyOf": Keywords.anyOf, 19 | "contains": Keywords.containsMinContainsMaxContains, 20 | "dependentSchemas": Keywords.dependentSchemas, 21 | "if": Keywords.if, 22 | "then": Keywords.then, 23 | "else": Keywords.else, 24 | "items": Keywords.items202012, 25 | "not": Keywords.not, 26 | "oneOf": Keywords.oneOf, 27 | "patternProperties": Keywords.patternProperties, 28 | "prefixItems": Keywords.tupleItems, 29 | "properties": Keywords.properties, 30 | "propertyNames": Keywords.propertyNames 31 | }); 32 | 33 | Core.defineVocabulary("https://json-schema.org/draft/2020-12/vocab/unevaluated", { 34 | "unevaluatedItems": Keywords.unevaluatedItems, 35 | "unevaluatedProperties": Keywords.unevaluatedProperties 36 | }); 37 | -------------------------------------------------------------------------------- /lib/fixtures/main.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json-schema.org/draft/2020-12/schema", 3 | 4 | "type": "object", 5 | "properties": { 6 | "foo": { "$ref": "string.schema.json" } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /lib/fixtures/mixed-schemes.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json-schema.org/draft/2020-12/schema", 3 | 4 | "type": "object", 5 | "properties": { 6 | "foo": { "$ref": "string.schema.json" }, 7 | "bar": { "$ref": "https://bundler.hyperjump.io/number" } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /lib/fixtures/string.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json-schema.org/draft/2020-12/schema", 3 | 4 | "type": "string" 5 | } 6 | -------------------------------------------------------------------------------- /lib/index.d.ts: -------------------------------------------------------------------------------- 1 | import type { Core, Schema, SchemaDocument, SchemaObject, InvalidSchemaError } from "@hyperjump/json-schema-core"; 2 | 3 | 4 | export type JsonSchemaBundler = { 5 | add: typeof Schema.add; 6 | get: typeof Schema.get; 7 | bundle: (schemaDoc: SchemaDocument, options?: BundleOptions) => Promise; 8 | FULL: "full"; 9 | FLAT: "flat"; 10 | URI: "uri"; 11 | UUID: "uuid"; 12 | setMetaOutputFormat: typeof Core.setMetaOutputFormat; 13 | setShouldMetaValidate: typeof Core.setShouldMetaValidate; 14 | FLAG: typeof Core.FLAG; 15 | BASIC: typeof Core.BASIC; 16 | DETAILED: typeof Core.DETAILED; 17 | VERBOSE: typeof Core.VERBOSE; 18 | InvalidSchemaError: typeof InvalidSchemaError; 19 | }; 20 | 21 | export type BundleOptions = { 22 | alwaysIncludeDialect?: boolean; 23 | bundleMode?: BundleMode; 24 | definitionNamingStrategy: DefinitionNamingStrategy; 25 | externalSchemas: string[]; 26 | }; 27 | 28 | export type BundleMode = JsonSchemaBundler["FULL"] | JsonSchemaBundler["FLAT"]; 29 | export type DefinitionNamingStrategy = JsonSchemaBundler["URI"] | JsonSchemaBundler["UUID"]; 30 | 31 | export const add: JsonSchemaBundler["add"]; 32 | export const get: JsonSchemaBundler["get"]; 33 | export const bundle: JsonSchemaBundler["bundle"]; 34 | export const FULL: JsonSchemaBundler["FULL"]; 35 | export const FLAT: JsonSchemaBundler["FLAT"]; 36 | export const URI: JsonSchemaBundler["URI"]; 37 | export const UUID: JsonSchemaBundler["UUID"]; 38 | export const setMetaOutputFormat: JsonSchemaBundler["setMetaOutputFormat"]; 39 | export const setShouldMetaValidate: JsonSchemaBundler["setShouldMetaValidate"]; 40 | export const FLAG: JsonSchemaBundler["FLAG"]; 41 | export const BASIC: JsonSchemaBundler["BASIC"]; 42 | export const DETAILED: JsonSchemaBundler["DETAILED"]; 43 | export const VERBOSE: JsonSchemaBundler["VERBOSE"]; 44 | 45 | export * from "@hyperjump/json-schema"; 46 | 47 | declare const jsonSchemaBundler: JsonSchemaBundler; 48 | export default jsonSchemaBundler; 49 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | const { v4: uuid } = require("uuid"); 2 | const JsonSchema = require("@hyperjump/json-schema"); 3 | const JsonPointer = require("@hyperjump/json-pointer"); 4 | const { Core, Schema, InvalidSchemaError } = require("@hyperjump/json-schema-core"); 5 | const Bundle = require("./core"); 6 | const { splitUri } = require("./common"); 7 | 8 | require("./draft-04"); 9 | require("./draft-06"); 10 | require("./draft-07"); 11 | require("./draft-2019-09"); 12 | require("./draft-2020-12"); 13 | 14 | 15 | const FULL = "full"; 16 | const FLAT = "flat"; 17 | const URI = "uri"; 18 | const UUID = "uuid"; 19 | 20 | const defaultOptions = { 21 | alwaysIncludeDialect: false, 22 | bundleMode: FLAT, 23 | definitionNamingStrategy: URI, 24 | externalSchemas: [] 25 | }; 26 | 27 | const bundle = async (schemaDoc, options = {}) => { 28 | const fullOptions = { ...defaultOptions, ...options }; 29 | 30 | const externalIds = await collectExternalIds(schemaDoc, fullOptions); 31 | 32 | const bundled = Schema.toSchema(schemaDoc, { 33 | includeEmbedded: fullOptions.bundleMode === FULL 34 | }); 35 | 36 | const bundlingLocation = Schema.getConfig(schemaDoc.dialectId, "bundlingLocation"); 37 | if (JsonPointer.get(bundlingLocation, bundled) === undefined && externalIds.size > 0) { 38 | JsonPointer.assign(bundlingLocation, bundled, {}); 39 | } 40 | 41 | for (const uri of externalIds.values()) { 42 | const externalSchema = await JsonSchema.get(uri); 43 | const embeddedSchema = Schema.toSchema(externalSchema, { 44 | parentId: schemaDoc.id, 45 | parentDialect: fullOptions.alwaysIncludeDialect ? "" : schemaDoc.dialectId, 46 | includeEmbedded: fullOptions.bundleMode === FULL 47 | }); 48 | let id; 49 | if (fullOptions.definitionNamingStrategy === URI) { 50 | const embeddedToken = Schema.getConfig(externalSchema.dialectId, "embeddedToken"); 51 | id = embeddedSchema[embeddedToken]; 52 | } else if (fullOptions.definitionNamingStrategy === UUID) { 53 | id = uuid(); 54 | } else { 55 | throw Error(`Unknown definition naming stragety: ${fullOptions.definitionNamingStrategy}`); 56 | } 57 | const pointer = JsonPointer.append(id, bundlingLocation); 58 | JsonPointer.assign(pointer, bundled, embeddedSchema); 59 | } 60 | 61 | return bundled; 62 | }; 63 | 64 | const collectExternalIds = async (schemaDoc, options) => { 65 | const { ast, schemaUri } = await Core.compile(schemaDoc); 66 | const subSchemaUris = new Set(); 67 | Bundle.collectExternalIds(schemaUri, subSchemaUris, ast, {}); 68 | const externalIds = new Set([...subSchemaUris] 69 | .map((uri) => splitUri(uri)[0]) 70 | .filter((uri) => !options.externalSchemas.includes(uri))); 71 | externalIds.delete(schemaDoc.id); 72 | 73 | return externalIds; 74 | }; 75 | 76 | module.exports = { 77 | add: JsonSchema.add, 78 | get: Schema.get, 79 | bundle: bundle, 80 | FULL: FULL, 81 | FLAT: FLAT, 82 | URI: URI, 83 | UUID: UUID, 84 | setMetaOutputFormat: Core.setMetaOutputFormat, 85 | setShouldMetaValidate: Core.setShouldMetaValidate, 86 | FLAG: Core.FLAG, 87 | BASIC: Core.BASIC, 88 | DETAILED: Core.DETAILED, 89 | VERBOSE: Core.VERBOSE, 90 | InvalidSchemaError: InvalidSchemaError 91 | }; 92 | -------------------------------------------------------------------------------- /lib/index.mjs: -------------------------------------------------------------------------------- 1 | import Bundler from "./index.js"; 2 | 3 | 4 | export const add = Bundler.add; 5 | export const get = Bundler.get; 6 | export const bundle = Bundler.bundle; 7 | export const FULL = Bundler.FULL; 8 | export const FLAT = Bundler.FLAT; 9 | export const URI = Bundler.URI; 10 | export const UUID = Bundler.UUID; 11 | export const setMetaOutputFormat = Bundler.setMetaOutputFormat; 12 | export const setShouldMetaValidate = Bundler.setShouldMetaValidate; 13 | export const FLAG = Bundler.FLAG; 14 | export const BASIC = Bundler.BASIC; 15 | export const DETAILED = Bundler.DETAILED; 16 | export const VERBOSE = Bundler.VERBOSE; 17 | export const InvalidSchemaError = Bundler.InvalidSchemaError; 18 | -------------------------------------------------------------------------------- /lib/keywords.js: -------------------------------------------------------------------------------- 1 | const JsonSchema = require("@hyperjump/json-schema"); 2 | const { Core } = require("@hyperjump/json-schema-core"); 3 | const Bundle = require("./core"); 4 | 5 | 6 | const validate = { 7 | ...JsonSchema.Keywords.validate, 8 | collectExternalIds: (schemaUri, externalIds, ast, dynamicAnchors) => { 9 | const nodes = ast[schemaUri][2]; 10 | if (externalIds.has(schemaUri) || typeof nodes === "boolean") { 11 | return; 12 | } 13 | externalIds.add(schemaUri); 14 | 15 | for (const [keywordId, , keywordValue] of nodes) { 16 | const keyword = Core.getKeyword(keywordId); 17 | 18 | if (keyword.collectExternalIds) { 19 | keyword.collectExternalIds(keywordValue, externalIds, ast, dynamicAnchors); 20 | } 21 | } 22 | } 23 | }; 24 | 25 | const ref = { 26 | ...JsonSchema.Keywords.ref, 27 | collectExternalIds: Bundle.collectExternalIds 28 | }; 29 | 30 | const additionalItems = { 31 | ...JsonSchema.Keywords.additionalItems, 32 | collectExternalIds: ([, additionalItems], externalIds, ast, dynamicAnchors) => { 33 | if (typeof additionalItems === "string") { 34 | Bundle.collectExternalIds(additionalItems, externalIds, ast, dynamicAnchors); 35 | } 36 | } 37 | }; 38 | 39 | const additionalProperties = { 40 | ...JsonSchema.Keywords.additionalProperties, 41 | collectExternalIds: ([, , additionalProperties], externalIds, ast, dynamicAnchors) => { 42 | if (typeof additionalProperties === "string") { 43 | Bundle.collectExternalIds(additionalProperties, externalIds, ast, dynamicAnchors); 44 | } 45 | } 46 | }; 47 | 48 | const additionalItems6 = { 49 | ...JsonSchema.Keywords.additionalItems6, 50 | collectExternalIds: ([, additionalItems], externalIds, ast, dynamicAnchors) => { 51 | Bundle.collectExternalIds(additionalItems, externalIds, ast, dynamicAnchors); 52 | } 53 | }; 54 | 55 | const additionalProperties6 = { 56 | ...JsonSchema.Keywords.additionalProperties6, 57 | collectExternalIds: ([, , additionalProperties], externalIds, ast, dynamicAnchors) => { 58 | Bundle.collectExternalIds(additionalProperties, externalIds, ast, dynamicAnchors); 59 | } 60 | }; 61 | 62 | const allOf = { 63 | ...JsonSchema.Keywords.allOf, 64 | collectExternalIds: (allOf, externalIds, ast, dynamicAnchors) => { 65 | allOf.forEach((schemaUri) => Bundle.collectExternalIds(schemaUri, externalIds, ast, dynamicAnchors)); 66 | } 67 | }; 68 | 69 | const anyOf = { 70 | ...JsonSchema.Keywords.anyOf, 71 | collectExternalIds: (anyOf, externalIds, ast, dynamicAnchors) => { 72 | anyOf.forEach((schemaUri) => Bundle.collectExternalIds(schemaUri, externalIds, ast, dynamicAnchors)); 73 | } 74 | }; 75 | 76 | const contains = { 77 | ...JsonSchema.Keywords.contains, 78 | collectExternalIds: Bundle.collectExternalIds 79 | }; 80 | 81 | const containsMinContainsMaxContains = { 82 | ...JsonSchema.Keywords.containsMinContainsMaxContains, 83 | collectExternalIds: ({ contains }, externalIds, ast, dynamicAnchors) => { 84 | Bundle.collectExternalIds(contains, externalIds, ast, dynamicAnchors); 85 | } 86 | }; 87 | 88 | const dependencies = { 89 | ...JsonSchema.Keywords.dependencies, 90 | collectExternalIds: (dependentSchemas, externalIds, ast, dynamicAnchors) => { 91 | Object.values(dependentSchemas).forEach(([, dependency]) => { 92 | if (typeof dependency === "string") { 93 | Bundle.collectExternalIds(dependency, externalIds, ast, dynamicAnchors); 94 | } 95 | }); 96 | } 97 | }; 98 | 99 | const dependentSchemas = { 100 | ...JsonSchema.Keywords.dependentSchemas, 101 | collectExternalIds: (dependentSchemas, externalIds, ast, dynamicAnchors) => { 102 | Object.values(dependentSchemas).forEach(([, schemaUri]) => Bundle.collectExternalIds(schemaUri, externalIds, ast, dynamicAnchors)); 103 | } 104 | }; 105 | 106 | const if_ = { 107 | ...JsonSchema.Keywords.if, 108 | collectExternalIds: Bundle.collectExternalIds 109 | }; 110 | 111 | const then = { 112 | ...JsonSchema.Keywords.then, 113 | collectExternalIds: ([, then], externalIds, ast, dynamicAnchors) => { 114 | Bundle.collectExternalIds(then, externalIds, ast, dynamicAnchors); 115 | } 116 | }; 117 | 118 | const else_ = { 119 | ...JsonSchema.Keywords.else, 120 | collectExternalIds: ([, elseSchema], externalIds, ast, dynamicAnchors) => { 121 | Bundle.collectExternalIds(elseSchema, externalIds, ast, dynamicAnchors); 122 | } 123 | }; 124 | 125 | const items = { 126 | ...JsonSchema.Keywords.items, 127 | collectExternalIds: (items, externalIds, ast, dynamicAnchors) => { 128 | if (typeof items === "string") { 129 | Bundle.collectExternalIds(items, externalIds, ast, dynamicAnchors); 130 | } else { 131 | items.forEach((schemaUri) => Bundle.collectExternalIds(schemaUri, externalIds, ast, dynamicAnchors)); 132 | } 133 | } 134 | }; 135 | 136 | const items202012 = { 137 | ...JsonSchema.Keywords.items202012, 138 | collectExternalIds: ([, items], externalIds, ast, dynamicAnchors) => { 139 | Bundle.collectExternalIds(items, externalIds, ast, dynamicAnchors); 140 | } 141 | }; 142 | 143 | const not = { 144 | ...JsonSchema.Keywords.not, 145 | collectExternalIds: Bundle.collectExternalIds 146 | }; 147 | 148 | const oneOf = { 149 | ...JsonSchema.Keywords.oneOf, 150 | collectExternalIds: (oneOf, externalIds, ast, dynamicAnchors) => { 151 | oneOf.forEach((schemaUri) => Bundle.collectExternalIds(schemaUri, externalIds, ast, dynamicAnchors)); 152 | } 153 | }; 154 | 155 | const patternProperties = { 156 | ...JsonSchema.Keywords.patternProperties, 157 | collectExternalIds: (patternProperties, externalIds, ast, dynamicAnchors) => { 158 | patternProperties.forEach(([, schemaUri]) => Bundle.collectExternalIds(schemaUri, externalIds, ast, dynamicAnchors)); 159 | } 160 | }; 161 | 162 | const tupleItems = { 163 | ...JsonSchema.Keywords.tupleItems, 164 | collectExternalIds: (tupleItems, externalIds, ast, dynamicAnchors) => { 165 | tupleItems.forEach((schemaUri) => Bundle.collectExternalIds(schemaUri, externalIds, ast, dynamicAnchors)); 166 | } 167 | }; 168 | 169 | const properties = { 170 | ...JsonSchema.Keywords.properties, 171 | collectExternalIds: (properties, externalIds, ast, dynamicAnchors) => { 172 | Object.values(properties).forEach((schemaUri) => Bundle.collectExternalIds(schemaUri, externalIds, ast, dynamicAnchors)); 173 | } 174 | }; 175 | 176 | const propertyNames = { 177 | ...JsonSchema.Keywords.propertyNames, 178 | collectExternalIds: Bundle.collectExternalIds 179 | }; 180 | 181 | const unevaluatedItems = { 182 | ...JsonSchema.Keywords.unevaluatedItems, 183 | collectExternalIds: ([, unevaluatedItems], externalIds, ast, dynamicAnchors) => { 184 | Bundle.collectExternalIds(unevaluatedItems, externalIds, ast, dynamicAnchors); 185 | } 186 | }; 187 | 188 | const unevaluatedProperties = { 189 | ...JsonSchema.Keywords.unevaluatedProperties, 190 | collectExternalIds: ([, unevaluatedProperties], externalIds, ast, dynamicAnchors) => { 191 | Bundle.collectExternalIds(unevaluatedProperties, externalIds, ast, dynamicAnchors); 192 | } 193 | }; 194 | 195 | module.exports = { 196 | validate, 197 | ref, 198 | additionalItems, 199 | additionalItems6, 200 | additionalProperties, 201 | additionalProperties6, 202 | allOf, 203 | anyOf, 204 | contains, 205 | containsMinContainsMaxContains, 206 | dependencies, 207 | dependentSchemas, 208 | if: if_, 209 | then, 210 | else: else_, 211 | items, 212 | items202012, 213 | not, 214 | oneOf, 215 | patternProperties, 216 | tupleItems, 217 | properties, 218 | propertyNames, 219 | unevaluatedItems, 220 | unevaluatedProperties 221 | }; 222 | -------------------------------------------------------------------------------- /lib/test-runner.spec.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs"; 2 | import { expect } from "chai"; 3 | import Bundler from "."; 4 | import type { BundleOptions } from "."; 5 | import type { SchemaObject } from "@hyperjump/json-schema"; 6 | 7 | 8 | type Test = { 9 | description: string; 10 | options?: BundleOptions; 11 | schema: SchemaObject | string; 12 | externalSchemas: SchemaObject[]; 13 | bundledSchema: SchemaObject; 14 | }; 15 | 16 | fs.readdirSync(`${__dirname}/tests`, { withFileTypes: true }) 17 | .filter((entry) => entry.isFile() && entry.name.endsWith(".json")) 18 | .forEach((entry) => { 19 | const file = `${__dirname}/tests/${entry.name}`; 20 | const suite = JSON.parse(fs.readFileSync(file, "utf8")) as Test[]; 21 | 22 | describe(entry.name, () => { 23 | suite.forEach((test) => { 24 | it(test.description, async () => { 25 | let uri; 26 | if (typeof test.schema === "string") { 27 | uri = `file://${__dirname}/fixtures/${test.schema}`; 28 | } else { 29 | Bundler.add(test.schema, "https://bundler.hyperjump.io/schema"); 30 | uri = "https://bundler.hyperjump.io/schema"; 31 | } 32 | test.externalSchemas.forEach((schema) => { 33 | Bundler.add(schema); 34 | }); 35 | const schema = await Bundler.get(uri); 36 | const bundle = await Bundler.bundle(schema, test.options); 37 | expect(bundle).eql(test.bundledSchema); 38 | }); 39 | }); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /lib/tests/advanced.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Recursive schema", 4 | "schema": { 5 | "$id": "https://bundler.hyperjump.io/main", 6 | "$schema": "https://json-schema.org/draft/2020-12/schema", 7 | 8 | "type": "object", 9 | "properties": { 10 | "tree": { "$ref": "/tree" } 11 | } 12 | }, 13 | "externalSchemas": [ 14 | { 15 | "$id": "https://bundler.hyperjump.io/tree", 16 | "$schema": "https://json-schema.org/draft/2020-12/schema", 17 | 18 | "type": "object", 19 | "properties": { 20 | "leaf": true, 21 | "branch": { "$ref": "#" } 22 | } 23 | } 24 | ], 25 | "bundledSchema": { 26 | "$id": "https://bundler.hyperjump.io/main", 27 | "$schema": "https://json-schema.org/draft/2020-12/schema", 28 | 29 | "type": "object", 30 | "properties": { 31 | "tree": { "$ref": "/tree" } 32 | }, 33 | 34 | "$defs": { 35 | "https://bundler.hyperjump.io/tree": { 36 | "$id": "https://bundler.hyperjump.io/tree", 37 | 38 | "type": "object", 39 | "properties": { 40 | "leaf": true, 41 | "branch": { "$ref": "#" } 42 | } 43 | } 44 | } 45 | } 46 | } 47 | ] 48 | -------------------------------------------------------------------------------- /lib/tests/basic.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "No external references", 4 | "schema": { 5 | "$id": "https://bundler.hyperjump.io/main", 6 | "$schema": "https://json-schema.org/draft/2020-12/schema", 7 | 8 | "type": "string" 9 | }, 10 | "externalSchemas": [], 11 | "bundledSchema": { 12 | "$id": "https://bundler.hyperjump.io/main", 13 | "$schema": "https://json-schema.org/draft/2020-12/schema", 14 | 15 | "type": "string" 16 | } 17 | }, 18 | { 19 | "description": "Anchors", 20 | "schema": { 21 | "$id": "https://bundler.hyperjump.io/main", 22 | "$schema": "https://json-schema.org/draft/2020-12/schema", 23 | 24 | "$anchor": "foo", 25 | "$dynamicAnchor": "bar", 26 | 27 | "type": "string", 28 | 29 | "allOf": [{ 30 | "$anchor": "aaa", 31 | "$dynamicAnchor": "bbb" 32 | }] 33 | }, 34 | "externalSchemas": [], 35 | "bundledSchema": { 36 | "$id": "https://bundler.hyperjump.io/main", 37 | "$schema": "https://json-schema.org/draft/2020-12/schema", 38 | 39 | "$anchor": "foo", 40 | "$dynamicAnchor": "bar", 41 | 42 | "type": "string", 43 | 44 | "allOf": [{ 45 | "$anchor": "aaa", 46 | "$dynamicAnchor": "bbb" 47 | }] 48 | } 49 | }, 50 | { 51 | "description": "One external reference", 52 | "schema": { 53 | "$id": "https://bundler.hyperjump.io/main", 54 | "$schema": "https://json-schema.org/draft/2020-12/schema", 55 | 56 | "type": "object", 57 | "properties": { 58 | "foo": { "$ref": "/string" } 59 | } 60 | }, 61 | "externalSchemas": [ 62 | { 63 | "$id": "https://bundler.hyperjump.io/string", 64 | "$schema": "https://json-schema.org/draft/2020-12/schema", 65 | 66 | "type": "string" 67 | } 68 | ], 69 | "bundledSchema": { 70 | "$id": "https://bundler.hyperjump.io/main", 71 | "$schema": "https://json-schema.org/draft/2020-12/schema", 72 | 73 | "type": "object", 74 | "properties": { 75 | "foo": { "$ref": "/string" } 76 | }, 77 | 78 | "$defs": { 79 | "https://bundler.hyperjump.io/string": { 80 | "$id": "https://bundler.hyperjump.io/string", 81 | 82 | "type": "string" 83 | } 84 | } 85 | } 86 | }, 87 | { 88 | "description": "Always include $schema option", 89 | "options": { 90 | "alwaysIncludeDialect": true 91 | }, 92 | "schema": { 93 | "$id": "https://bundler.hyperjump.io/main", 94 | "$schema": "https://json-schema.org/draft/2020-12/schema", 95 | 96 | "type": "object", 97 | "properties": { 98 | "foo": { "$ref": "/string" } 99 | } 100 | }, 101 | "externalSchemas": [ 102 | { 103 | "$id": "https://bundler.hyperjump.io/string", 104 | "$schema": "https://json-schema.org/draft/2020-12/schema", 105 | 106 | "type": "string" 107 | } 108 | ], 109 | "bundledSchema": { 110 | "$id": "https://bundler.hyperjump.io/main", 111 | "$schema": "https://json-schema.org/draft/2020-12/schema", 112 | 113 | "type": "object", 114 | "properties": { 115 | "foo": { "$ref": "/string" } 116 | }, 117 | 118 | "$defs": { 119 | "https://bundler.hyperjump.io/string": { 120 | "$id": "https://bundler.hyperjump.io/string", 121 | "$schema": "https://json-schema.org/draft/2020-12/schema", 122 | 123 | "type": "string" 124 | } 125 | } 126 | } 127 | }, 128 | { 129 | "description": "External reference to a different dialect", 130 | "schema": { 131 | "$id": "https://bundler.hyperjump.io/main", 132 | "$schema": "https://json-schema.org/draft/2020-12/schema", 133 | 134 | "type": "object", 135 | "properties": { 136 | "foo": { "$ref": "/string" } 137 | } 138 | }, 139 | "externalSchemas": [ 140 | { 141 | "$id": "https://bundler.hyperjump.io/string", 142 | "$schema": "https://json-schema.org/draft/2019-09/schema", 143 | 144 | "type": "string" 145 | } 146 | ], 147 | "bundledSchema": { 148 | "$id": "https://bundler.hyperjump.io/main", 149 | "$schema": "https://json-schema.org/draft/2020-12/schema", 150 | 151 | "type": "object", 152 | "properties": { 153 | "foo": { "$ref": "/string" } 154 | }, 155 | 156 | "$defs": { 157 | "https://bundler.hyperjump.io/string": { 158 | "$id": "https://bundler.hyperjump.io/string", 159 | "$schema": "https://json-schema.org/draft/2019-09/schema", 160 | 161 | "type": "string" 162 | } 163 | } 164 | } 165 | }, 166 | { 167 | "description": "Multiple external references", 168 | "schema": { 169 | "$id": "https://bundler.hyperjump.io/main", 170 | "$schema": "https://json-schema.org/draft/2020-12/schema", 171 | 172 | "type": "object", 173 | "properties": { 174 | "foo": { "$ref": "/string" }, 175 | "bar": { "$ref": "/number" } 176 | } 177 | }, 178 | "externalSchemas": [ 179 | { 180 | "$id": "https://bundler.hyperjump.io/string", 181 | "$schema": "https://json-schema.org/draft/2020-12/schema", 182 | 183 | "type": "string" 184 | }, 185 | { 186 | "$id": "https://bundler.hyperjump.io/number", 187 | "$schema": "https://json-schema.org/draft/2020-12/schema", 188 | 189 | "type": "number" 190 | } 191 | ], 192 | "bundledSchema": { 193 | "$id": "https://bundler.hyperjump.io/main", 194 | "$schema": "https://json-schema.org/draft/2020-12/schema", 195 | 196 | "type": "object", 197 | "properties": { 198 | "foo": { "$ref": "/string" }, 199 | "bar": { "$ref": "/number" } 200 | }, 201 | 202 | "$defs": { 203 | "https://bundler.hyperjump.io/string": { 204 | "$id": "https://bundler.hyperjump.io/string", 205 | 206 | "type": "string" 207 | }, 208 | "https://bundler.hyperjump.io/number": { 209 | "$id": "https://bundler.hyperjump.io/number", 210 | 211 | "type": "number" 212 | } 213 | } 214 | } 215 | }, 216 | { 217 | "description": "Bundle with draft-04/7 style refrences", 218 | "schema": { 219 | "$id": "https://bundler.hyperjump.io/main", 220 | "$schema": "http://json-schema.org/draft-07/schema", 221 | 222 | "type": "object", 223 | "properties": { 224 | "foo": { "$ref": "/string" } 225 | } 226 | }, 227 | "externalSchemas": [ 228 | { 229 | "$id": "https://bundler.hyperjump.io/string", 230 | "$schema": "http://json-schema.org/draft-07/schema", 231 | 232 | "type": "string" 233 | } 234 | ], 235 | "bundledSchema": { 236 | "$id": "https://bundler.hyperjump.io/main", 237 | "$schema": "http://json-schema.org/draft-07/schema", 238 | 239 | "type": "object", 240 | "properties": { 241 | "foo": { "$ref": "/string" } 242 | }, 243 | 244 | "definitions": { 245 | "https://bundler.hyperjump.io/string": { 246 | "$id": "https://bundler.hyperjump.io/string", 247 | 248 | "type": "string" 249 | } 250 | } 251 | } 252 | } 253 | ] 254 | -------------------------------------------------------------------------------- /lib/tests/external-schemas.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Exclude external schemas in bundle", 4 | "options": { 5 | "externalSchemas": ["https://bundler.hyperjump.io/number"] 6 | }, 7 | "schema": { 8 | "$id": "https://bundler.hyperjump.io/main", 9 | "$schema": "https://json-schema.org/draft/2020-12/schema", 10 | 11 | "type": "object", 12 | "properties": { 13 | "foo": { "$ref": "/string" }, 14 | "bar": { "$ref": "/number" } 15 | } 16 | }, 17 | "externalSchemas": [ 18 | { 19 | "$id": "https://bundler.hyperjump.io/string", 20 | "$schema": "https://json-schema.org/draft/2020-12/schema", 21 | 22 | "type": "string" 23 | }, 24 | { 25 | "$id": "https://bundler.hyperjump.io/number", 26 | "$schema": "https://json-schema.org/draft/2020-12/schema", 27 | 28 | "type": "number" 29 | } 30 | ], 31 | "bundledSchema": { 32 | "$id": "https://bundler.hyperjump.io/main", 33 | "$schema": "https://json-schema.org/draft/2020-12/schema", 34 | 35 | "type": "object", 36 | "properties": { 37 | "foo": { "$ref": "/string" }, 38 | "bar": { "$ref": "/number" } 39 | }, 40 | 41 | "$defs": { 42 | "https://bundler.hyperjump.io/string": { 43 | "$id": "https://bundler.hyperjump.io/string", 44 | 45 | "type": "string" 46 | } 47 | } 48 | } 49 | } 50 | ] 51 | -------------------------------------------------------------------------------- /lib/tests/file.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Use relative paths for files", 4 | "schema": "main.schema.json", 5 | "externalSchemas": [], 6 | "bundledSchema": { 7 | "$schema": "https://json-schema.org/draft/2020-12/schema", 8 | 9 | "type": "object", 10 | "properties": { 11 | "foo": { "$ref": "string.schema.json" } 12 | }, 13 | 14 | "$defs": { 15 | "string.schema.json": { 16 | "$id": "string.schema.json", 17 | 18 | "type": "string" 19 | } 20 | } 21 | } 22 | }, 23 | { 24 | "description": "Allow mix of http and file if main is file", 25 | "schema": "mixed-schemes.schema.json", 26 | "externalSchemas": [ 27 | { 28 | "$id": "https://bundler.hyperjump.io/number", 29 | "$schema": "https://json-schema.org/draft/2020-12/schema", 30 | 31 | "type": "number" 32 | } 33 | ], 34 | "bundledSchema": { 35 | "$schema": "https://json-schema.org/draft/2020-12/schema", 36 | 37 | "type": "object", 38 | "properties": { 39 | "foo": { "$ref": "string.schema.json" }, 40 | "bar": { "$ref": "https://bundler.hyperjump.io/number" } 41 | }, 42 | 43 | "$defs": { 44 | "string.schema.json": { 45 | "$id": "string.schema.json", 46 | 47 | "type": "string" 48 | }, 49 | "https://bundler.hyperjump.io/number": { 50 | "$id": "https://bundler.hyperjump.io/number", 51 | 52 | "type": "number" 53 | } 54 | } 55 | } 56 | } 57 | ] 58 | -------------------------------------------------------------------------------- /lib/tests/flat-bundle.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Flatten already bundled schema", 4 | "schema": { 5 | "$id": "https://bundler.hyperjump.io/main", 6 | "$schema": "https://json-schema.org/draft/2020-12/schema", 7 | 8 | "type": "object", 9 | "properties": { 10 | "foo": { "$ref": "/string" } 11 | }, 12 | 13 | "$defs": { 14 | "string": { 15 | "$id": "https://bundler.hyperjump.io/string", 16 | "$schema": "https://json-schema.org/draft/2020-12/schema", 17 | 18 | "type": "string" 19 | } 20 | } 21 | }, 22 | "externalSchemas": [], 23 | "bundledSchema": { 24 | "$id": "https://bundler.hyperjump.io/main", 25 | "$schema": "https://json-schema.org/draft/2020-12/schema", 26 | 27 | "type": "object", 28 | "properties": { 29 | "foo": { "$ref": "/string" } 30 | }, 31 | 32 | "$defs": { 33 | "https://bundler.hyperjump.io/string": { 34 | "$id": "https://bundler.hyperjump.io/string", 35 | 36 | "type": "string" 37 | } 38 | } 39 | } 40 | }, 41 | { 42 | "description": "Flatten deeply bundled schema", 43 | "schema": { 44 | "$id": "https://bundler.hyperjump.io/main", 45 | "$schema": "https://json-schema.org/draft/2020-12/schema", 46 | 47 | "type": "object", 48 | "properties": { 49 | "foo": { "$ref": "/nested" }, 50 | "bar": { "$ref": "/string" } 51 | }, 52 | 53 | "$defs": { 54 | "nested": { 55 | "$id": "https://bundler.hyperjump.io/nested", 56 | "$schema": "https://json-schema.org/draft/2020-12/schema", 57 | 58 | "type": "object", 59 | "properties": { 60 | "baz": { "$ref": "/string" } 61 | }, 62 | 63 | "$defs": { 64 | "string": { 65 | "$id": "https://bundler.hyperjump.io/string", 66 | "$schema": "https://json-schema.org/draft/2020-12/schema", 67 | 68 | "type": "string" 69 | } 70 | } 71 | } 72 | } 73 | }, 74 | "externalSchemas": [], 75 | "bundledSchema": { 76 | "$id": "https://bundler.hyperjump.io/main", 77 | "$schema": "https://json-schema.org/draft/2020-12/schema", 78 | 79 | "type": "object", 80 | "properties": { 81 | "foo": { "$ref": "/nested" }, 82 | "bar": { "$ref": "/string" } 83 | }, 84 | 85 | "$defs": { 86 | "https://bundler.hyperjump.io/nested": { 87 | "$id": "https://bundler.hyperjump.io/nested", 88 | 89 | "type": "object", 90 | "properties": { 91 | "baz": { "$ref": "/string" } 92 | }, 93 | 94 | "$defs": {} 95 | }, 96 | "https://bundler.hyperjump.io/string": { 97 | "$id": "https://bundler.hyperjump.io/string", 98 | 99 | "type": "string" 100 | } 101 | } 102 | } 103 | }, 104 | { 105 | "description": "Flatten deeply bundled from external schema", 106 | "schema": { 107 | "$id": "https://bundler.hyperjump.io/main", 108 | "$schema": "https://json-schema.org/draft/2020-12/schema", 109 | 110 | "type": "object", 111 | "properties": { 112 | "foo": { "$ref": "/nested" }, 113 | "bar": { "$ref": "/string" } 114 | } 115 | }, 116 | "externalSchemas": [ 117 | { 118 | "$id": "https://bundler.hyperjump.io/nested", 119 | "$schema": "https://json-schema.org/draft/2020-12/schema", 120 | 121 | "type": "object", 122 | "properties": { 123 | "baz": { "$ref": "/string" } 124 | }, 125 | 126 | "$defs": { 127 | "string": { 128 | "$id": "https://bundler.hyperjump.io/string", 129 | "$schema": "https://json-schema.org/draft/2020-12/schema", 130 | 131 | "type": "string" 132 | } 133 | } 134 | } 135 | ], 136 | "bundledSchema": { 137 | "$id": "https://bundler.hyperjump.io/main", 138 | "$schema": "https://json-schema.org/draft/2020-12/schema", 139 | 140 | "type": "object", 141 | "properties": { 142 | "foo": { "$ref": "/nested" }, 143 | "bar": { "$ref": "/string" } 144 | }, 145 | 146 | "$defs": { 147 | "https://bundler.hyperjump.io/nested": { 148 | "$id": "https://bundler.hyperjump.io/nested", 149 | 150 | "type": "object", 151 | "properties": { 152 | "baz": { "$ref": "/string" } 153 | }, 154 | 155 | "$defs": {} 156 | }, 157 | "https://bundler.hyperjump.io/string": { 158 | "$id": "https://bundler.hyperjump.io/string", 159 | 160 | "type": "string" 161 | } 162 | } 163 | } 164 | } 165 | ] 166 | -------------------------------------------------------------------------------- /lib/tests/full-bundle.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Full bundle with already bundled schema", 4 | "options": { 5 | "bundleMode": "full" 6 | }, 7 | "schema": { 8 | "$id": "https://bundler.hyperjump.io/main", 9 | "$schema": "https://json-schema.org/draft/2020-12/schema", 10 | 11 | "type": "object", 12 | "properties": { 13 | "foo": { "$ref": "/string" } 14 | }, 15 | 16 | "$defs": { 17 | "string": { 18 | "$id": "https://bundler.hyperjump.io/string", 19 | "$schema": "https://json-schema.org/draft/2020-12/schema", 20 | 21 | "type": "string" 22 | } 23 | } 24 | }, 25 | "externalSchemas": [], 26 | "bundledSchema": { 27 | "$id": "https://bundler.hyperjump.io/main", 28 | "$schema": "https://json-schema.org/draft/2020-12/schema", 29 | 30 | "type": "object", 31 | "properties": { 32 | "foo": { "$ref": "/string" } 33 | }, 34 | 35 | "$defs": { 36 | "string": { 37 | "$id": "https://bundler.hyperjump.io/string", 38 | "$schema": "https://json-schema.org/draft/2020-12/schema", 39 | 40 | "type": "string" 41 | }, 42 | "https://bundler.hyperjump.io/string": { 43 | "$id": "https://bundler.hyperjump.io/string", 44 | 45 | "type": "string" 46 | } 47 | } 48 | } 49 | }, 50 | { 51 | "description": "Full bundle with deeply bundled schema", 52 | "options": { 53 | "bundleMode": "full" 54 | }, 55 | "schema": { 56 | "$id": "https://bundler.hyperjump.io/main", 57 | "$schema": "https://json-schema.org/draft/2020-12/schema", 58 | 59 | "type": "object", 60 | "properties": { 61 | "foo": { "$ref": "/nested" }, 62 | "bar": { "$ref": "/string" } 63 | }, 64 | 65 | "$defs": { 66 | "nested": { 67 | "$id": "https://bundler.hyperjump.io/nested", 68 | "$schema": "https://json-schema.org/draft/2020-12/schema", 69 | 70 | "type": "object", 71 | "properties": { 72 | "baz": { "$ref": "/string" } 73 | }, 74 | 75 | "$defs": { 76 | "string": { 77 | "$id": "https://bundler.hyperjump.io/string", 78 | "$schema": "https://json-schema.org/draft/2020-12/schema", 79 | 80 | "type": "string" 81 | } 82 | } 83 | } 84 | } 85 | }, 86 | "externalSchemas": [], 87 | "bundledSchema": { 88 | "$id": "https://bundler.hyperjump.io/main", 89 | "$schema": "https://json-schema.org/draft/2020-12/schema", 90 | 91 | "type": "object", 92 | "properties": { 93 | "foo": { "$ref": "/nested" }, 94 | "bar": { "$ref": "/string" } 95 | }, 96 | 97 | "$defs": { 98 | "nested": { 99 | "$id": "https://bundler.hyperjump.io/nested", 100 | "$schema": "https://json-schema.org/draft/2020-12/schema", 101 | 102 | "type": "object", 103 | "properties": { 104 | "baz": { "$ref": "/string" } 105 | }, 106 | 107 | "$defs": { 108 | "string": { 109 | "$id": "https://bundler.hyperjump.io/string", 110 | "$schema": "https://json-schema.org/draft/2020-12/schema", 111 | 112 | "type": "string" 113 | } 114 | } 115 | }, 116 | "https://bundler.hyperjump.io/nested": { 117 | "$id": "https://bundler.hyperjump.io/nested", 118 | 119 | "type": "object", 120 | "properties": { 121 | "baz": { "$ref": "/string" } 122 | }, 123 | 124 | "$defs": { 125 | "string": { 126 | "$id": "https://bundler.hyperjump.io/string", 127 | "$schema": "https://json-schema.org/draft/2020-12/schema", 128 | 129 | "type": "string" 130 | } 131 | } 132 | }, 133 | "https://bundler.hyperjump.io/string": { 134 | "$id": "https://bundler.hyperjump.io/string", 135 | 136 | "type": "string" 137 | } 138 | } 139 | } 140 | }, 141 | { 142 | "description": "Full bundle with deeply bundled from external schema", 143 | "options": { 144 | "bundleMode": "full" 145 | }, 146 | "schema": { 147 | "$id": "https://bundler.hyperjump.io/main", 148 | "$schema": "https://json-schema.org/draft/2020-12/schema", 149 | 150 | "type": "object", 151 | "properties": { 152 | "foo": { "$ref": "/nested" }, 153 | "bar": { "$ref": "/string" } 154 | } 155 | }, 156 | "externalSchemas": [ 157 | { 158 | "$id": "https://bundler.hyperjump.io/nested", 159 | "$schema": "https://json-schema.org/draft/2020-12/schema", 160 | 161 | "type": "object", 162 | "properties": { 163 | "baz": { "$ref": "/string" } 164 | }, 165 | 166 | "$defs": { 167 | "string": { 168 | "$id": "https://bundler.hyperjump.io/string", 169 | "$schema": "https://json-schema.org/draft/2020-12/schema", 170 | 171 | "type": "string" 172 | } 173 | } 174 | } 175 | ], 176 | "bundledSchema": { 177 | "$id": "https://bundler.hyperjump.io/main", 178 | "$schema": "https://json-schema.org/draft/2020-12/schema", 179 | 180 | "type": "object", 181 | "properties": { 182 | "foo": { "$ref": "/nested" }, 183 | "bar": { "$ref": "/string" } 184 | }, 185 | 186 | "$defs": { 187 | "https://bundler.hyperjump.io/nested": { 188 | "$id": "https://bundler.hyperjump.io/nested", 189 | 190 | "type": "object", 191 | "properties": { 192 | "baz": { "$ref": "/string" } 193 | }, 194 | 195 | "$defs": { 196 | "string": { 197 | "$id": "https://bundler.hyperjump.io/string", 198 | "$schema": "https://json-schema.org/draft/2020-12/schema", 199 | 200 | "type": "string" 201 | } 202 | } 203 | }, 204 | "https://bundler.hyperjump.io/string": { 205 | "$id": "https://bundler.hyperjump.io/string", 206 | 207 | "type": "string" 208 | } 209 | } 210 | } 211 | } 212 | ] 213 | -------------------------------------------------------------------------------- /lib/tests/keywords.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Bundle schema from $ref", 4 | "schema": { 5 | "$id": "https://bundler.hyperjump.io/main", 6 | "$schema": "https://json-schema.org/draft/2020-12/schema", 7 | 8 | "$ref": "/string" 9 | }, 10 | "externalSchemas": [ 11 | { 12 | "$id": "https://bundler.hyperjump.io/string", 13 | "$schema": "https://json-schema.org/draft/2020-12/schema", 14 | 15 | "type": "string" 16 | } 17 | ], 18 | "bundledSchema": { 19 | "$id": "https://bundler.hyperjump.io/main", 20 | "$schema": "https://json-schema.org/draft/2020-12/schema", 21 | 22 | "$ref": "/string", 23 | 24 | "$defs": { 25 | "https://bundler.hyperjump.io/string": { 26 | "$id": "https://bundler.hyperjump.io/string", 27 | 28 | "type": "string" 29 | } 30 | } 31 | } 32 | }, 33 | { 34 | "description": "Bundle schema from additionalItems draft-04", 35 | "schema": { 36 | "id": "https://bundler.hyperjump.io/main", 37 | "$schema": "http://json-schema.org/draft-04/schema#", 38 | 39 | "additionalItems": { "$ref": "/string" } 40 | }, 41 | "externalSchemas": [ 42 | { 43 | "id": "https://bundler.hyperjump.io/string", 44 | "$schema": "http://json-schema.org/draft-04/schema#", 45 | 46 | "type": "string" 47 | } 48 | ], 49 | "bundledSchema": { 50 | "id": "https://bundler.hyperjump.io/main", 51 | "$schema": "http://json-schema.org/draft-04/schema", 52 | 53 | "additionalItems": { "$ref": "/string" }, 54 | 55 | "definitions": { 56 | "https://bundler.hyperjump.io/string": { 57 | "id": "https://bundler.hyperjump.io/string", 58 | 59 | "type": "string" 60 | } 61 | } 62 | } 63 | }, 64 | { 65 | "description": "Bundle boolean schema from additionalItems draft-04", 66 | "schema": { 67 | "id": "https://bundler.hyperjump.io/main", 68 | "$schema": "http://json-schema.org/draft-04/schema#", 69 | 70 | "additionalItems": false 71 | }, 72 | "externalSchemas": [ 73 | { 74 | "id": "https://bundler.hyperjump.io/string", 75 | "$schema": "http://json-schema.org/draft-04/schema#", 76 | 77 | "type": "string" 78 | } 79 | ], 80 | "bundledSchema": { 81 | "id": "https://bundler.hyperjump.io/main", 82 | "$schema": "http://json-schema.org/draft-04/schema", 83 | 84 | "additionalItems": false 85 | } 86 | }, 87 | { 88 | "description": "Bundle schema from additionalItems", 89 | "schema": { 90 | "$id": "https://bundler.hyperjump.io/main", 91 | "$schema": "https://json-schema.org/draft/2019-09/schema", 92 | 93 | "additionalItems": { "$ref": "/string" } 94 | }, 95 | "externalSchemas": [ 96 | { 97 | "$id": "https://bundler.hyperjump.io/string", 98 | "$schema": "https://json-schema.org/draft/2019-09/schema", 99 | 100 | "type": "string" 101 | } 102 | ], 103 | "bundledSchema": { 104 | "$id": "https://bundler.hyperjump.io/main", 105 | "$schema": "https://json-schema.org/draft/2019-09/schema", 106 | 107 | "additionalItems": { "$ref": "/string" }, 108 | 109 | "$defs": { 110 | "https://bundler.hyperjump.io/string": { 111 | "$id": "https://bundler.hyperjump.io/string", 112 | 113 | "type": "string" 114 | } 115 | } 116 | } 117 | }, 118 | { 119 | "description": "Bundle schema from additionalProperties draft-04", 120 | "schema": { 121 | "id": "https://bundler.hyperjump.io/main", 122 | "$schema": "http://json-schema.org/draft-04/schema#", 123 | 124 | "additionalProperties": { "$ref": "/string" } 125 | }, 126 | "externalSchemas": [ 127 | { 128 | "id": "https://bundler.hyperjump.io/string", 129 | "$schema": "http://json-schema.org/draft-04/schema#", 130 | 131 | "type": "string" 132 | } 133 | ], 134 | "bundledSchema": { 135 | "id": "https://bundler.hyperjump.io/main", 136 | "$schema": "http://json-schema.org/draft-04/schema", 137 | 138 | "additionalProperties": { "$ref": "/string" }, 139 | 140 | "definitions": { 141 | "https://bundler.hyperjump.io/string": { 142 | "id": "https://bundler.hyperjump.io/string", 143 | 144 | "type": "string" 145 | } 146 | } 147 | } 148 | }, 149 | { 150 | "description": "Bundle boolean schema from additionalProperties draft-04", 151 | "schema": { 152 | "id": "https://bundler.hyperjump.io/main", 153 | "$schema": "http://json-schema.org/draft-04/schema#", 154 | 155 | "additionalProperties": false 156 | }, 157 | "externalSchemas": [ 158 | { 159 | "id": "https://bundler.hyperjump.io/string", 160 | "$schema": "http://json-schema.org/draft-04/schema#", 161 | 162 | "type": "string" 163 | } 164 | ], 165 | "bundledSchema": { 166 | "id": "https://bundler.hyperjump.io/main", 167 | "$schema": "http://json-schema.org/draft-04/schema", 168 | 169 | "additionalProperties": false 170 | } 171 | }, 172 | { 173 | "description": "Bundle schema from additionalProperties", 174 | "schema": { 175 | "$id": "https://bundler.hyperjump.io/main", 176 | "$schema": "https://json-schema.org/draft/2020-12/schema", 177 | 178 | "additionalProperties": { "$ref": "/string" } 179 | }, 180 | "externalSchemas": [ 181 | { 182 | "$id": "https://bundler.hyperjump.io/string", 183 | "$schema": "https://json-schema.org/draft/2020-12/schema", 184 | 185 | "type": "string" 186 | } 187 | ], 188 | "bundledSchema": { 189 | "$id": "https://bundler.hyperjump.io/main", 190 | "$schema": "https://json-schema.org/draft/2020-12/schema", 191 | 192 | "additionalProperties": { "$ref": "/string" }, 193 | 194 | "$defs": { 195 | "https://bundler.hyperjump.io/string": { 196 | "$id": "https://bundler.hyperjump.io/string", 197 | 198 | "type": "string" 199 | } 200 | } 201 | } 202 | }, 203 | { 204 | "description": "Bundle schema from allOf", 205 | "schema": { 206 | "$id": "https://bundler.hyperjump.io/main", 207 | "$schema": "https://json-schema.org/draft/2020-12/schema", 208 | 209 | "allOf": [{ "$ref": "/string" }] 210 | }, 211 | "externalSchemas": [ 212 | { 213 | "$id": "https://bundler.hyperjump.io/string", 214 | "$schema": "https://json-schema.org/draft/2020-12/schema", 215 | 216 | "type": "string" 217 | } 218 | ], 219 | "bundledSchema": { 220 | "$id": "https://bundler.hyperjump.io/main", 221 | "$schema": "https://json-schema.org/draft/2020-12/schema", 222 | 223 | "allOf": [{ "$ref": "/string" }], 224 | 225 | "$defs": { 226 | "https://bundler.hyperjump.io/string": { 227 | "$id": "https://bundler.hyperjump.io/string", 228 | 229 | "type": "string" 230 | } 231 | } 232 | } 233 | }, 234 | { 235 | "description": "Bundle schema from anyOf", 236 | "schema": { 237 | "$id": "https://bundler.hyperjump.io/main", 238 | "$schema": "https://json-schema.org/draft/2020-12/schema", 239 | 240 | "anyOf": [{ "$ref": "/string" }] 241 | }, 242 | "externalSchemas": [ 243 | { 244 | "$id": "https://bundler.hyperjump.io/string", 245 | "$schema": "https://json-schema.org/draft/2020-12/schema", 246 | 247 | "type": "string" 248 | } 249 | ], 250 | "bundledSchema": { 251 | "$id": "https://bundler.hyperjump.io/main", 252 | "$schema": "https://json-schema.org/draft/2020-12/schema", 253 | 254 | "anyOf": [{ "$ref": "/string" }], 255 | 256 | "$defs": { 257 | "https://bundler.hyperjump.io/string": { 258 | "$id": "https://bundler.hyperjump.io/string", 259 | 260 | "type": "string" 261 | } 262 | } 263 | } 264 | }, 265 | { 266 | "description": "Bundle schema from contains draft-07", 267 | "schema": { 268 | "$id": "https://bundler.hyperjump.io/main", 269 | "$schema": "http://json-schema.org/draft-07/schema#", 270 | 271 | "contains": { "$ref": "/string" } 272 | }, 273 | "externalSchemas": [ 274 | { 275 | "$id": "https://bundler.hyperjump.io/string", 276 | "$schema": "http://json-schema.org/draft-07/schema#", 277 | 278 | "type": "string" 279 | } 280 | ], 281 | "bundledSchema": { 282 | "$id": "https://bundler.hyperjump.io/main", 283 | "$schema": "http://json-schema.org/draft-07/schema", 284 | 285 | "contains": { "$ref": "/string" }, 286 | 287 | "definitions": { 288 | "https://bundler.hyperjump.io/string": { 289 | "$id": "https://bundler.hyperjump.io/string", 290 | 291 | "type": "string" 292 | } 293 | } 294 | } 295 | }, 296 | { 297 | "description": "Bundle schema from contains", 298 | "schema": { 299 | "$id": "https://bundler.hyperjump.io/main", 300 | "$schema": "https://json-schema.org/draft/2020-12/schema", 301 | 302 | "contains": { "$ref": "/string" } 303 | }, 304 | "externalSchemas": [ 305 | { 306 | "$id": "https://bundler.hyperjump.io/string", 307 | "$schema": "https://json-schema.org/draft/2020-12/schema", 308 | 309 | "type": "string" 310 | } 311 | ], 312 | "bundledSchema": { 313 | "$id": "https://bundler.hyperjump.io/main", 314 | "$schema": "https://json-schema.org/draft/2020-12/schema", 315 | 316 | "contains": { "$ref": "/string" }, 317 | 318 | "$defs": { 319 | "https://bundler.hyperjump.io/string": { 320 | "$id": "https://bundler.hyperjump.io/string", 321 | 322 | "type": "string" 323 | } 324 | } 325 | } 326 | }, 327 | { 328 | "description": "Bundle schema from dependencies", 329 | "schema": { 330 | "$id": "https://bundler.hyperjump.io/main", 331 | "$schema": "http://json-schema.org/draft-07/schema#", 332 | 333 | "dependencies": { 334 | "foo": { "$ref": "/string" } 335 | } 336 | }, 337 | "externalSchemas": [ 338 | { 339 | "$id": "https://bundler.hyperjump.io/string", 340 | "$schema": "http://json-schema.org/draft-07/schema#", 341 | 342 | "type": "string" 343 | } 344 | ], 345 | "bundledSchema": { 346 | "$id": "https://bundler.hyperjump.io/main", 347 | "$schema": "http://json-schema.org/draft-07/schema", 348 | 349 | "dependencies": { 350 | "foo": { "$ref": "/string" } 351 | }, 352 | 353 | "definitions": { 354 | "https://bundler.hyperjump.io/string": { 355 | "$id": "https://bundler.hyperjump.io/string", 356 | 357 | "type": "string" 358 | } 359 | } 360 | } 361 | }, 362 | { 363 | "description": "Bundle schema from string-array dependencies", 364 | "schema": { 365 | "$id": "https://bundler.hyperjump.io/main", 366 | "$schema": "http://json-schema.org/draft-07/schema#", 367 | 368 | "dependencies": { 369 | "foo": ["bar"] 370 | } 371 | }, 372 | "externalSchemas": [ 373 | { 374 | "$id": "https://bundler.hyperjump.io/string", 375 | "$schema": "http://json-schema.org/draft-07/schema#", 376 | 377 | "type": "string" 378 | } 379 | ], 380 | "bundledSchema": { 381 | "$id": "https://bundler.hyperjump.io/main", 382 | "$schema": "http://json-schema.org/draft-07/schema", 383 | 384 | "dependencies": { 385 | "foo": ["bar"] 386 | } 387 | } 388 | }, 389 | { 390 | "description": "Bundle schema from dependentSchemas", 391 | "schema": { 392 | "$id": "https://bundler.hyperjump.io/main", 393 | "$schema": "https://json-schema.org/draft/2020-12/schema", 394 | 395 | "dependentSchemas": { 396 | "foo": { "$ref": "/string" } 397 | } 398 | }, 399 | "externalSchemas": [ 400 | { 401 | "$id": "https://bundler.hyperjump.io/string", 402 | "$schema": "https://json-schema.org/draft/2020-12/schema", 403 | 404 | "type": "string" 405 | } 406 | ], 407 | "bundledSchema": { 408 | "$id": "https://bundler.hyperjump.io/main", 409 | "$schema": "https://json-schema.org/draft/2020-12/schema", 410 | 411 | "dependentSchemas": { 412 | "foo": { "$ref": "/string" } 413 | }, 414 | 415 | "$defs": { 416 | "https://bundler.hyperjump.io/string": { 417 | "$id": "https://bundler.hyperjump.io/string", 418 | 419 | "type": "string" 420 | } 421 | } 422 | } 423 | }, 424 | { 425 | "description": "Bundle schema from if", 426 | "schema": { 427 | "$id": "https://bundler.hyperjump.io/main", 428 | "$schema": "https://json-schema.org/draft/2020-12/schema", 429 | 430 | "if": { "$ref": "/string" } 431 | }, 432 | "externalSchemas": [ 433 | { 434 | "$id": "https://bundler.hyperjump.io/string", 435 | "$schema": "https://json-schema.org/draft/2020-12/schema", 436 | 437 | "type": "string" 438 | } 439 | ], 440 | "bundledSchema": { 441 | "$id": "https://bundler.hyperjump.io/main", 442 | "$schema": "https://json-schema.org/draft/2020-12/schema", 443 | 444 | "if": { "$ref": "/string" }, 445 | 446 | "$defs": { 447 | "https://bundler.hyperjump.io/string": { 448 | "$id": "https://bundler.hyperjump.io/string", 449 | 450 | "type": "string" 451 | } 452 | } 453 | } 454 | }, 455 | { 456 | "description": "Bundle schema from then", 457 | "schema": { 458 | "$id": "https://bundler.hyperjump.io/main", 459 | "$schema": "https://json-schema.org/draft/2020-12/schema", 460 | 461 | "if": true, 462 | "then": { "$ref": "/string" } 463 | }, 464 | "externalSchemas": [ 465 | { 466 | "$id": "https://bundler.hyperjump.io/string", 467 | "$schema": "https://json-schema.org/draft/2020-12/schema", 468 | 469 | "type": "string" 470 | } 471 | ], 472 | "bundledSchema": { 473 | "$id": "https://bundler.hyperjump.io/main", 474 | "$schema": "https://json-schema.org/draft/2020-12/schema", 475 | 476 | "if": true, 477 | "then": { "$ref": "/string" }, 478 | 479 | "$defs": { 480 | "https://bundler.hyperjump.io/string": { 481 | "$id": "https://bundler.hyperjump.io/string", 482 | 483 | "type": "string" 484 | } 485 | } 486 | } 487 | }, 488 | { 489 | "description": "Bundle schema from else", 490 | "schema": { 491 | "$id": "https://bundler.hyperjump.io/main", 492 | "$schema": "https://json-schema.org/draft/2020-12/schema", 493 | 494 | "if": false, 495 | "else": { "$ref": "/string" } 496 | }, 497 | "externalSchemas": [ 498 | { 499 | "$id": "https://bundler.hyperjump.io/string", 500 | "$schema": "https://json-schema.org/draft/2020-12/schema", 501 | 502 | "type": "string" 503 | } 504 | ], 505 | "bundledSchema": { 506 | "$id": "https://bundler.hyperjump.io/main", 507 | "$schema": "https://json-schema.org/draft/2020-12/schema", 508 | 509 | "if": false, 510 | "else": { "$ref": "/string" }, 511 | 512 | "$defs": { 513 | "https://bundler.hyperjump.io/string": { 514 | "$id": "https://bundler.hyperjump.io/string", 515 | 516 | "type": "string" 517 | } 518 | } 519 | } 520 | }, 521 | { 522 | "description": "Bundle schema from items 2019-09", 523 | "schema": { 524 | "$id": "https://bundler.hyperjump.io/main", 525 | "$schema": "https://json-schema.org/draft/2019-09/schema", 526 | 527 | "items": { "$ref": "/string" } 528 | }, 529 | "externalSchemas": [ 530 | { 531 | "$id": "https://bundler.hyperjump.io/string", 532 | "$schema": "https://json-schema.org/draft/2019-09/schema", 533 | 534 | "type": "string" 535 | } 536 | ], 537 | "bundledSchema": { 538 | "$id": "https://bundler.hyperjump.io/main", 539 | "$schema": "https://json-schema.org/draft/2019-09/schema", 540 | 541 | "items": { "$ref": "/string" }, 542 | 543 | "$defs": { 544 | "https://bundler.hyperjump.io/string": { 545 | "$id": "https://bundler.hyperjump.io/string", 546 | 547 | "type": "string" 548 | } 549 | } 550 | } 551 | }, 552 | { 553 | "description": "Bundle schema from tuple items 2019-09", 554 | "schema": { 555 | "$id": "https://bundler.hyperjump.io/main", 556 | "$schema": "https://json-schema.org/draft/2019-09/schema", 557 | 558 | "items": [{ "$ref": "/string" }] 559 | }, 560 | "externalSchemas": [ 561 | { 562 | "$id": "https://bundler.hyperjump.io/string", 563 | "$schema": "https://json-schema.org/draft/2019-09/schema", 564 | 565 | "type": "string" 566 | } 567 | ], 568 | "bundledSchema": { 569 | "$id": "https://bundler.hyperjump.io/main", 570 | "$schema": "https://json-schema.org/draft/2019-09/schema", 571 | 572 | "items": [{ "$ref": "/string" }], 573 | 574 | "$defs": { 575 | "https://bundler.hyperjump.io/string": { 576 | "$id": "https://bundler.hyperjump.io/string", 577 | 578 | "type": "string" 579 | } 580 | } 581 | } 582 | }, 583 | { 584 | "description": "Bundle schema from items", 585 | "schema": { 586 | "$id": "https://bundler.hyperjump.io/main", 587 | "$schema": "https://json-schema.org/draft/2020-12/schema", 588 | 589 | "items": { "$ref": "/string" } 590 | }, 591 | "externalSchemas": [ 592 | { 593 | "$id": "https://bundler.hyperjump.io/string", 594 | "$schema": "https://json-schema.org/draft/2020-12/schema", 595 | 596 | "type": "string" 597 | } 598 | ], 599 | "bundledSchema": { 600 | "$id": "https://bundler.hyperjump.io/main", 601 | "$schema": "https://json-schema.org/draft/2020-12/schema", 602 | 603 | "items": { "$ref": "/string" }, 604 | 605 | "$defs": { 606 | "https://bundler.hyperjump.io/string": { 607 | "$id": "https://bundler.hyperjump.io/string", 608 | 609 | "type": "string" 610 | } 611 | } 612 | } 613 | }, 614 | { 615 | "description": "Bundle schema from not", 616 | "schema": { 617 | "$id": "https://bundler.hyperjump.io/main", 618 | "$schema": "https://json-schema.org/draft/2020-12/schema", 619 | 620 | "not": { "$ref": "/string" } 621 | }, 622 | "externalSchemas": [ 623 | { 624 | "$id": "https://bundler.hyperjump.io/string", 625 | "$schema": "https://json-schema.org/draft/2020-12/schema", 626 | 627 | "type": "string" 628 | } 629 | ], 630 | "bundledSchema": { 631 | "$id": "https://bundler.hyperjump.io/main", 632 | "$schema": "https://json-schema.org/draft/2020-12/schema", 633 | 634 | "not": { "$ref": "/string" }, 635 | 636 | "$defs": { 637 | "https://bundler.hyperjump.io/string": { 638 | "$id": "https://bundler.hyperjump.io/string", 639 | 640 | "type": "string" 641 | } 642 | } 643 | } 644 | }, 645 | { 646 | "description": "Bundle schema from oneOf", 647 | "schema": { 648 | "$id": "https://bundler.hyperjump.io/main", 649 | "$schema": "https://json-schema.org/draft/2020-12/schema", 650 | 651 | "oneOf": [{ "$ref": "/string" }] 652 | }, 653 | "externalSchemas": [ 654 | { 655 | "$id": "https://bundler.hyperjump.io/string", 656 | "$schema": "https://json-schema.org/draft/2020-12/schema", 657 | 658 | "type": "string" 659 | } 660 | ], 661 | "bundledSchema": { 662 | "$id": "https://bundler.hyperjump.io/main", 663 | "$schema": "https://json-schema.org/draft/2020-12/schema", 664 | 665 | "oneOf": [{ "$ref": "/string" }], 666 | 667 | "$defs": { 668 | "https://bundler.hyperjump.io/string": { 669 | "$id": "https://bundler.hyperjump.io/string", 670 | 671 | "type": "string" 672 | } 673 | } 674 | } 675 | }, 676 | { 677 | "description": "Bundle schema from patternProperties", 678 | "schema": { 679 | "$id": "https://bundler.hyperjump.io/main", 680 | "$schema": "https://json-schema.org/draft/2020-12/schema", 681 | 682 | "patternProperties": { 683 | ".": { "$ref": "/string" } 684 | } 685 | }, 686 | "externalSchemas": [ 687 | { 688 | "$id": "https://bundler.hyperjump.io/string", 689 | "$schema": "https://json-schema.org/draft/2020-12/schema", 690 | 691 | "type": "string" 692 | } 693 | ], 694 | "bundledSchema": { 695 | "$id": "https://bundler.hyperjump.io/main", 696 | "$schema": "https://json-schema.org/draft/2020-12/schema", 697 | 698 | "patternProperties": { 699 | ".": { "$ref": "/string" } 700 | }, 701 | 702 | "$defs": { 703 | "https://bundler.hyperjump.io/string": { 704 | "$id": "https://bundler.hyperjump.io/string", 705 | 706 | "type": "string" 707 | } 708 | } 709 | } 710 | }, 711 | { 712 | "description": "Bundle schema from prefixItems", 713 | "schema": { 714 | "$id": "https://bundler.hyperjump.io/main", 715 | "$schema": "https://json-schema.org/draft/2020-12/schema", 716 | 717 | "prefixItems": [{ "$ref": "/string" }] 718 | }, 719 | "externalSchemas": [ 720 | { 721 | "$id": "https://bundler.hyperjump.io/string", 722 | "$schema": "https://json-schema.org/draft/2020-12/schema", 723 | 724 | "type": "string" 725 | } 726 | ], 727 | "bundledSchema": { 728 | "$id": "https://bundler.hyperjump.io/main", 729 | "$schema": "https://json-schema.org/draft/2020-12/schema", 730 | 731 | "prefixItems": [{ "$ref": "/string" }], 732 | 733 | "$defs": { 734 | "https://bundler.hyperjump.io/string": { 735 | "$id": "https://bundler.hyperjump.io/string", 736 | 737 | "type": "string" 738 | } 739 | } 740 | } 741 | }, 742 | { 743 | "description": "Bundle schema from properties", 744 | "schema": { 745 | "$id": "https://bundler.hyperjump.io/main", 746 | "$schema": "https://json-schema.org/draft/2020-12/schema", 747 | 748 | "properties": { 749 | "foo": { "$ref": "/string" } 750 | } 751 | }, 752 | "externalSchemas": [ 753 | { 754 | "$id": "https://bundler.hyperjump.io/string", 755 | "$schema": "https://json-schema.org/draft/2020-12/schema", 756 | 757 | "type": "string" 758 | } 759 | ], 760 | "bundledSchema": { 761 | "$id": "https://bundler.hyperjump.io/main", 762 | "$schema": "https://json-schema.org/draft/2020-12/schema", 763 | 764 | "properties": { 765 | "foo": { "$ref": "/string" } 766 | }, 767 | 768 | "$defs": { 769 | "https://bundler.hyperjump.io/string": { 770 | "$id": "https://bundler.hyperjump.io/string", 771 | 772 | "type": "string" 773 | } 774 | } 775 | } 776 | }, 777 | { 778 | "description": "Bundle schema from propertyNames", 779 | "schema": { 780 | "$id": "https://bundler.hyperjump.io/main", 781 | "$schema": "https://json-schema.org/draft/2020-12/schema", 782 | 783 | "propertyNames": { "$ref": "/string" } 784 | }, 785 | "externalSchemas": [ 786 | { 787 | "$id": "https://bundler.hyperjump.io/string", 788 | "$schema": "https://json-schema.org/draft/2020-12/schema", 789 | 790 | "type": "string" 791 | } 792 | ], 793 | "bundledSchema": { 794 | "$id": "https://bundler.hyperjump.io/main", 795 | "$schema": "https://json-schema.org/draft/2020-12/schema", 796 | 797 | "propertyNames": { "$ref": "/string" }, 798 | 799 | "$defs": { 800 | "https://bundler.hyperjump.io/string": { 801 | "$id": "https://bundler.hyperjump.io/string", 802 | 803 | "type": "string" 804 | } 805 | } 806 | } 807 | }, 808 | { 809 | "description": "Bundle schema from unevaluatedItems", 810 | "schema": { 811 | "$id": "https://bundler.hyperjump.io/main", 812 | "$schema": "https://json-schema.org/draft/2020-12/schema", 813 | 814 | "unevaluatedItems": { "$ref": "/string" } 815 | }, 816 | "externalSchemas": [ 817 | { 818 | "$id": "https://bundler.hyperjump.io/string", 819 | "$schema": "https://json-schema.org/draft/2020-12/schema", 820 | 821 | "type": "string" 822 | } 823 | ], 824 | "bundledSchema": { 825 | "$id": "https://bundler.hyperjump.io/main", 826 | "$schema": "https://json-schema.org/draft/2020-12/schema", 827 | 828 | "unevaluatedItems": { "$ref": "/string" }, 829 | 830 | "$defs": { 831 | "https://bundler.hyperjump.io/string": { 832 | "$id": "https://bundler.hyperjump.io/string", 833 | 834 | "type": "string" 835 | } 836 | } 837 | } 838 | }, 839 | { 840 | "description": "Bundle schema from unevaluatedProperties", 841 | "schema": { 842 | "$id": "https://bundler.hyperjump.io/main", 843 | "$schema": "https://json-schema.org/draft/2020-12/schema", 844 | 845 | "unevaluatedProperties": { "$ref": "/string" } 846 | }, 847 | "externalSchemas": [ 848 | { 849 | "$id": "https://bundler.hyperjump.io/string", 850 | "$schema": "https://json-schema.org/draft/2020-12/schema", 851 | 852 | "type": "string" 853 | } 854 | ], 855 | "bundledSchema": { 856 | "$id": "https://bundler.hyperjump.io/main", 857 | "$schema": "https://json-schema.org/draft/2020-12/schema", 858 | 859 | "unevaluatedProperties": { "$ref": "/string" }, 860 | 861 | "$defs": { 862 | "https://bundler.hyperjump.io/string": { 863 | "$id": "https://bundler.hyperjump.io/string", 864 | 865 | "type": "string" 866 | } 867 | } 868 | } 869 | } 870 | ] 871 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@hyperjump/json-schema-bundle", 3 | "version": "0.4.0", 4 | "description": "A tool for bundling JSON Schema documents", 5 | "main": "lib/index.js", 6 | "exports": { 7 | "require": "./lib/index.js", 8 | "import": "./lib/index.mjs" 9 | }, 10 | "scripts": { 11 | "clean": "xargs -a .gitignore rm -rf", 12 | "lint": "eslint lib", 13 | "test": "mocha --require ts-node/register 'lib/**/*.spec.ts'", 14 | "build": "rollup --config rollup.config.js", 15 | "prepublishOnly": "npm run build" 16 | }, 17 | "repository": "github:hyperjump-io/json-schema-bundle", 18 | "keywords": [ 19 | "JSON Schema", 20 | "json-schema", 21 | "jsonschema", 22 | "schema", 23 | "bundle", 24 | "bundler", 25 | "$ref", 26 | "external", 27 | "reference", 28 | "Compound Schema Document", 29 | "embedded" 30 | ], 31 | "author": "Jason Desrosiers ", 32 | "license": "MIT", 33 | "funding": { 34 | "type": "github", 35 | "url": "https://github.com/sponsors/jdesrosiers" 36 | }, 37 | "dependencies": { 38 | "@hyperjump/json-schema": "^0.23.0", 39 | "uuid": "^8.3.2" 40 | }, 41 | "devDependencies": { 42 | "@rollup/plugin-commonjs": "*", 43 | "@rollup/plugin-node-resolve": "*", 44 | "@types/chai": "*", 45 | "@types/mocha": "*", 46 | "@types/uuid": "*", 47 | "@typescript-eslint/eslint-plugin": "*", 48 | "@typescript-eslint/parser": "*", 49 | "chai": "*", 50 | "eslint": "*", 51 | "eslint-import-resolver-node": "*", 52 | "eslint-import-resolver-typescript": "*", 53 | "eslint-plugin-import": "*", 54 | "mocha": "*", 55 | "rollup": "*", 56 | "rollup-plugin-terser": "*", 57 | "ts-node": "*", 58 | "typescript": "*" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | const { nodeResolve } = require("@rollup/plugin-node-resolve"); 2 | const commonjs = require("@rollup/plugin-commonjs"); 3 | const { terser } = require("rollup-plugin-terser"); 4 | 5 | 6 | const flatMap = (fn, list) => list.reduce((acc, x) => acc.concat(fn(x)), []); 7 | const combine = (lists, items) => flatMap((item) => lists.map((list) => [...list, item]), items); 8 | const combinations = (...lists) => lists.reduce(combine, [[]]); 9 | 10 | const formats = ["amd", "cjs", "esm", "iife", "umd", "system"]; 11 | const minify = [true, false]; 12 | const config = combinations(formats, minify); 13 | 14 | module.exports = config.map(([format, minify]) => ({ 15 | input: "lib/index.js", 16 | output: { 17 | format: format, 18 | file: `dist/json-schema-bundler-${format}${minify ? ".min" : ""}.js`, 19 | name: "JSB", 20 | sourcemap: true, 21 | exports: "named" 22 | }, 23 | plugins: [ 24 | nodeResolve({ 25 | browser: true 26 | }), 27 | commonjs(), 28 | minify && terser() 29 | ] 30 | })); 31 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es2015", 5 | "moduleResolution": "node", 6 | "resolveJsonModule": true, 7 | "esModuleInterop": true, 8 | "strict": true, 9 | "allowJs": true 10 | } 11 | } 12 | --------------------------------------------------------------------------------