@json-schema-tools/referencer 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/build/index.d.ts +10 -1
- package/build/index.js +20 -13
- package/package.json +12 -12
- package/CHANGELOG.md +0 -53
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ The input schema, as well as all of its subschemas must have titles. Their title
|
|
|
17
17
|
Features:
|
|
18
18
|
- Cyclic schemas become cyclic references
|
|
19
19
|
- Completely synchronous
|
|
20
|
+
- immutable by default, option to mutate in place.
|
|
20
21
|
- No external dependencies
|
|
21
22
|
- Fully typed against the generated [meta-schema typings](https://github.com/json-schema-tools/meta-schema/)
|
|
22
23
|
- magically makes your json schema smaller.
|
package/build/index.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export declare class NoTitleError implements Error {
|
|
|
5
5
|
message: string;
|
|
6
6
|
constructor(schema: JSONSchema, parentSchema: JSONSchema);
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Options that can be passed into the Referencer.
|
|
10
|
+
*/
|
|
11
|
+
export interface ReferencerOptions {
|
|
12
|
+
/**
|
|
13
|
+
* If true, the schema passed in will be referenced in-place, mutating the original. Default is false.
|
|
14
|
+
*/
|
|
15
|
+
mutate?: boolean;
|
|
16
|
+
}
|
|
8
17
|
/**
|
|
9
18
|
* Returns the schema where all subschemas have been replaced with $refs and added to definitions.
|
|
10
19
|
*
|
|
@@ -20,4 +29,4 @@ export declare class NoTitleError implements Error {
|
|
|
20
29
|
* @category SchemaImprover
|
|
21
30
|
*
|
|
22
31
|
*/
|
|
23
|
-
export default function referencer(s: JSONSchema): JSONSchema;
|
|
32
|
+
export default function referencer(s: JSONSchema, options?: ReferencerOptions): JSONSchema;
|
package/build/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var stringifyCircular = function (obj) {
|
|
|
25
25
|
return JSON.stringify(obj, function (key, value) {
|
|
26
26
|
if (typeof value === "object" && value !== null) {
|
|
27
27
|
if (cache.indexOf(value) !== -1) {
|
|
28
|
-
return "[Circular: "
|
|
28
|
+
return "[Circular: ".concat(value.title ? value.title : "NoTitle", "]");
|
|
29
29
|
}
|
|
30
30
|
cache.push(value);
|
|
31
31
|
}
|
|
@@ -42,13 +42,13 @@ var NoTitleError = /** @class */ (function () {
|
|
|
42
42
|
schemaStr = JSON.stringify(schema);
|
|
43
43
|
}
|
|
44
44
|
catch (e) {
|
|
45
|
-
schemaStr = exports.stringifyCircular(schema);
|
|
45
|
+
schemaStr = (0, exports.stringifyCircular)(schema);
|
|
46
46
|
}
|
|
47
47
|
try {
|
|
48
48
|
parentSchemaStr = JSON.stringify(parentSchema);
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
|
51
|
-
parentSchemaStr = exports.stringifyCircular(parentSchema);
|
|
51
|
+
parentSchemaStr = (0, exports.stringifyCircular)(parentSchema);
|
|
52
52
|
}
|
|
53
53
|
this.message = [
|
|
54
54
|
"Title is required on subschemas.",
|
|
@@ -64,6 +64,9 @@ var NoTitleError = /** @class */ (function () {
|
|
|
64
64
|
return NoTitleError;
|
|
65
65
|
}());
|
|
66
66
|
exports.NoTitleError = NoTitleError;
|
|
67
|
+
var defaultReferencerOptions = {
|
|
68
|
+
mutate: false,
|
|
69
|
+
};
|
|
67
70
|
/**
|
|
68
71
|
* Returns the schema where all subschemas have been replaced with $refs and added to definitions.
|
|
69
72
|
*
|
|
@@ -79,26 +82,27 @@ exports.NoTitleError = NoTitleError;
|
|
|
79
82
|
* @category SchemaImprover
|
|
80
83
|
*
|
|
81
84
|
*/
|
|
82
|
-
function referencer(s) {
|
|
85
|
+
function referencer(s, options) {
|
|
86
|
+
if (options === void 0) { options = defaultReferencerOptions; }
|
|
83
87
|
var definitions = {};
|
|
84
|
-
traverse_1.default(s, function (subSchema, isRootCycle) {
|
|
88
|
+
var newS = (0, traverse_1.default)(s, function (subSchema, isRootCycle) {
|
|
85
89
|
var t = "";
|
|
86
90
|
if (isRootCycle && subSchema !== true && subSchema !== false) {
|
|
87
91
|
if (subSchema.$ref) {
|
|
88
92
|
var title = subSchema.$ref.replace("#/definitions/", "");
|
|
89
93
|
var hasDefForRef = definitions[title];
|
|
90
94
|
if (hasDefForRef === undefined) {
|
|
91
|
-
throw new Error("Encountered unknown $ref: "
|
|
95
|
+
throw new Error("Encountered unknown $ref: ".concat(subSchema.$ref));
|
|
92
96
|
}
|
|
93
97
|
return subSchema;
|
|
94
98
|
}
|
|
95
99
|
if (subSchema === s) {
|
|
96
100
|
definitions[s.title] = { $ref: "#" };
|
|
97
|
-
return { $ref: "#/definitions/"
|
|
101
|
+
return { $ref: "#/definitions/".concat(s.title) };
|
|
98
102
|
}
|
|
99
103
|
definitions[subSchema.title] = __assign({}, subSchema);
|
|
100
104
|
deleteAllProps(subSchema);
|
|
101
|
-
subSchema.$ref = "#/definitions/"
|
|
105
|
+
subSchema.$ref = "#/definitions/".concat(subSchema.title);
|
|
102
106
|
return subSchema;
|
|
103
107
|
}
|
|
104
108
|
if (subSchema === true) {
|
|
@@ -119,13 +123,16 @@ function referencer(s) {
|
|
|
119
123
|
t = subSchema.title;
|
|
120
124
|
definitions[t] = __assign({}, subSchema);
|
|
121
125
|
deleteAllProps(subSchema);
|
|
122
|
-
subSchema.$ref = "#/definitions/"
|
|
126
|
+
subSchema.$ref = "#/definitions/".concat(t);
|
|
123
127
|
}
|
|
124
128
|
return subSchema;
|
|
125
|
-
}, { mutable:
|
|
126
|
-
if (
|
|
127
|
-
|
|
129
|
+
}, { mutable: options.mutate, skipFirstMutation: true });
|
|
130
|
+
if (options.mutate === true) {
|
|
131
|
+
newS = s;
|
|
132
|
+
}
|
|
133
|
+
if (typeof newS === "object" && Object.keys(definitions).length > 0) {
|
|
134
|
+
newS.definitions = __assign(__assign({}, newS.definitions), definitions);
|
|
128
135
|
}
|
|
129
|
-
return
|
|
136
|
+
return newS;
|
|
130
137
|
}
|
|
131
138
|
exports.default = referencer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-schema-tools/referencer",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
"!build/**/*.test.*"
|
|
27
27
|
],
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@json-schema-tools/meta-schema": "^1.
|
|
30
|
-
"@types/jest": "^
|
|
31
|
-
"@types/node": "^
|
|
32
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
33
|
-
"@typescript-eslint/parser": "^
|
|
34
|
-
"eslint": "^
|
|
35
|
-
"jest": "^
|
|
36
|
-
"ts-jest": "^
|
|
37
|
-
"typedoc": "^0.
|
|
38
|
-
"typescript": "4.
|
|
29
|
+
"@json-schema-tools/meta-schema": "^1.7.0",
|
|
30
|
+
"@types/jest": "^29.2.0",
|
|
31
|
+
"@types/node": "^18.11.7",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
33
|
+
"@typescript-eslint/parser": "^5.41.0",
|
|
34
|
+
"eslint": "^8.26.0",
|
|
35
|
+
"jest": "^29.2.2",
|
|
36
|
+
"ts-jest": "^29.0.3",
|
|
37
|
+
"typedoc": "^0.23.18",
|
|
38
|
+
"typescript": "^4.8.4"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@json-schema-tools/traverse": "^1.
|
|
41
|
+
"@json-schema-tools/traverse": "^1.10.1"
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://github.com/json-schema-tools/referencer#readme",
|
|
44
44
|
"description": "Get a copy of a JSON Schema where all subschemas are turned into `$ref`s with corresponding definitions section."
|
package/CHANGELOG.md
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
## [1.0.5](https://github.com/json-schema-tools/referencer/compare/1.0.4...1.0.5) (2021-06-24)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* update to new meta-schema ([521cb6f](https://github.com/json-schema-tools/referencer/commit/521cb6fc253040d6dda4b9f657fe18697b9e8891))
|
|
7
|
-
|
|
8
|
-
## [1.0.4](https://github.com/json-schema-tools/referencer/compare/1.0.3...1.0.4) (2021-06-08)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
### Bug Fixes
|
|
12
|
-
|
|
13
|
-
* linting fixup ([04d6243](https://github.com/json-schema-tools/referencer/commit/04d62436e0e40348d4fe5dcc1d14901f4ebcdab2))
|
|
14
|
-
* update deps ([7bfb05b](https://github.com/json-schema-tools/referencer/commit/7bfb05b7cee8ef07de40cd8187b437b20a25ff22))
|
|
15
|
-
|
|
16
|
-
## [1.0.3](https://github.com/json-schema-tools/referencer/compare/1.0.2...1.0.3) (2020-11-03)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
### Bug Fixes
|
|
20
|
-
|
|
21
|
-
* add docs ([a67a07f](https://github.com/json-schema-tools/referencer/commit/a67a07f1e7aa96e86edee05a2800092d5f8189cc))
|
|
22
|
-
|
|
23
|
-
## [1.0.2](https://github.com/json-schema-tools/referencer/compare/1.0.1...1.0.2) (2020-10-23)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### Bug Fixes
|
|
27
|
-
|
|
28
|
-
* add funding ([606b55b](https://github.com/json-schema-tools/referencer/commit/606b55b4d2170c412aa7b3e5ba19098b98a8e1bd))
|
|
29
|
-
|
|
30
|
-
## [1.0.1](https://github.com/json-schema-tools/referencer/compare/1.0.0...1.0.1) (2020-10-23)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
### Bug Fixes
|
|
34
|
-
|
|
35
|
-
* add pristine items ([9f68961](https://github.com/json-schema-tools/referencer/commit/9f689612c9975b53eec21e7bf9b797a23611e88a))
|
|
36
|
-
* lock node version ([7ee46e8](https://github.com/json-schema-tools/referencer/commit/7ee46e8dc5da95055eff24412d2870ccf8ae1c5e))
|
|
37
|
-
* remove dependabot badge ([adb559f](https://github.com/json-schema-tools/referencer/commit/adb559f23701c0727ac77b850af1920ee0668512))
|
|
38
|
-
* update all deps ([ecc2d58](https://github.com/json-schema-tools/referencer/commit/ecc2d584946d03ca981d8c9dbae1fdf6d54a1a23))
|
|
39
|
-
* update eslint ([2862bcb](https://github.com/json-schema-tools/referencer/commit/2862bcbf5591fd7c8fbffd6f762cd5a6858504ff))
|
|
40
|
-
* update readme ([a6702e6](https://github.com/json-schema-tools/referencer/commit/a6702e6d060a847eb6ca80763eb68b096807842e))
|
|
41
|
-
|
|
42
|
-
# 1.0.0 (2020-08-29)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### Bug Fixes
|
|
46
|
-
|
|
47
|
-
* build stuff ([d669ace](https://github.com/json-schema-tools/referencer/commit/d669acee8ed69f659d78bad3ab3d6d080ca5bdaa))
|
|
48
|
-
* tests working ([94f270e](https://github.com/json-schema-tools/referencer/commit/94f270e063cca68e4c0cc6790d749b685b3e4269))
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
### Features
|
|
52
|
-
|
|
53
|
-
* first ([cf7d97a](https://github.com/json-schema-tools/referencer/commit/cf7d97a694be116376e7eccdb1ae370af2affe58))
|