@apidevtools/json-schema-ref-parser 15.3.1 → 15.3.2
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/dist/lib/bundle.js +12 -9
- package/dist/lib/dereference.js +12 -8
- package/dist/lib/index.js +3 -0
- package/dist/lib/parse.d.ts +6 -1
- package/dist/lib/parse.js +15 -1
- package/dist/lib/pointer.d.ts +4 -0
- package/dist/lib/pointer.js +28 -2
- package/dist/lib/ref.d.ts +4 -0
- package/dist/lib/ref.js +4 -0
- package/dist/lib/refs.d.ts +3 -0
- package/dist/lib/refs.js +24 -8
- package/dist/lib/resolve-external.js +22 -9
- package/dist/lib/types/index.d.ts +11 -0
- package/dist/lib/util/schema-resources.d.ts +6 -0
- package/dist/lib/util/schema-resources.js +47 -0
- package/lib/bundle.ts +47 -7
- package/lib/dereference.ts +19 -1
- package/lib/index.ts +3 -0
- package/lib/parse.ts +22 -1
- package/lib/pointer.ts +31 -2
- package/lib/ref.ts +5 -0
- package/lib/refs.ts +30 -8
- package/lib/resolve-external.ts +45 -7
- package/lib/types/index.ts +13 -0
- package/lib/util/schema-resources.ts +73 -0
- package/package.json +12 -12
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as url from "./url.js";
|
|
2
|
+
import type { ParserOptions } from "../options.js";
|
|
3
|
+
import type { JSONSchema } from "../index.js";
|
|
4
|
+
import type $Refs from "../refs.js";
|
|
5
|
+
|
|
6
|
+
export function getSchemaBasePath(basePath: string, value: unknown) {
|
|
7
|
+
const schemaId = getSchemaId(value);
|
|
8
|
+
return schemaId ? url.resolve(basePath, schemaId) : basePath;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function usesDynamicIdScope(value: unknown) {
|
|
12
|
+
if (!value || typeof value !== "object" || ArrayBuffer.isView(value)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const schema = (value as { $schema?: unknown }).$schema;
|
|
17
|
+
if (
|
|
18
|
+
typeof schema === "string" &&
|
|
19
|
+
(schema.includes("draft/2019-09/") || schema.includes("draft/2020-12/") || schema.includes("oas/3.1/"))
|
|
20
|
+
) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const openapi = (value as { openapi?: unknown }).openapi;
|
|
25
|
+
return typeof openapi === "string" && /^3\.1(?:\.|$)/.test(openapi);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function registerSchemaResources<S extends object = JSONSchema, O extends ParserOptions<S> = ParserOptions<S>>(
|
|
29
|
+
$refs: $Refs<S, O>,
|
|
30
|
+
basePath: string,
|
|
31
|
+
value: unknown,
|
|
32
|
+
pathType?: string | unknown,
|
|
33
|
+
dynamicIdScope = false,
|
|
34
|
+
) {
|
|
35
|
+
if (!dynamicIdScope) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const seen = new Set<object>();
|
|
40
|
+
|
|
41
|
+
const visit = (node: unknown, scopeBase: string) => {
|
|
42
|
+
if (!node || typeof node !== "object" || ArrayBuffer.isView(node) || seen.has(node)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
seen.add(node);
|
|
47
|
+
|
|
48
|
+
const nextScopeBase = getSchemaBasePath(scopeBase, node);
|
|
49
|
+
if (nextScopeBase !== scopeBase) {
|
|
50
|
+
$refs._addAlias(nextScopeBase, node as S, pathType, dynamicIdScope);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (const key of Object.keys(node)) {
|
|
54
|
+
visit((node as Record<string, unknown>)[key], nextScopeBase);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
visit(value, basePath);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getSchemaId(value: unknown): string | undefined {
|
|
62
|
+
if (
|
|
63
|
+
value &&
|
|
64
|
+
typeof value === "object" &&
|
|
65
|
+
"$id" in value &&
|
|
66
|
+
typeof (value as { $id?: unknown }).$id === "string" &&
|
|
67
|
+
(value as { $id: string }).$id.length > 0
|
|
68
|
+
) {
|
|
69
|
+
return (value as { $id: string }).$id;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apidevtools/json-schema-ref-parser",
|
|
3
|
-
"version": "15.3.
|
|
3
|
+
"version": "15.3.2",
|
|
4
4
|
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/lib/index.d.ts",
|
|
@@ -75,29 +75,29 @@
|
|
|
75
75
|
"js-yaml": "^4.1.1"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@eslint/compat": "^2.0.
|
|
78
|
+
"@eslint/compat": "^2.0.3",
|
|
79
79
|
"@eslint/js": "^10.0.1",
|
|
80
80
|
"@types/eslint": "^9.6.1",
|
|
81
81
|
"@types/js-yaml": "^4.0.9",
|
|
82
82
|
"@types/json-schema": "^7.0.15",
|
|
83
83
|
"@types/node": "^25",
|
|
84
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
85
|
-
"@typescript-eslint/parser": "^8.
|
|
86
|
-
"@vitest/coverage-v8": "^4.
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^8.57.2",
|
|
85
|
+
"@typescript-eslint/parser": "^8.57.2",
|
|
86
|
+
"@vitest/coverage-v8": "^4.1.1",
|
|
87
87
|
"cross-env": "^10.1.0",
|
|
88
|
-
"eslint": "^10.0
|
|
88
|
+
"eslint": "^10.1.0",
|
|
89
89
|
"eslint-config-prettier": "^10.1.8",
|
|
90
90
|
"eslint-plugin-import": "^2.32.0",
|
|
91
91
|
"eslint-plugin-prettier": "^5.5.5",
|
|
92
92
|
"eslint-plugin-promise": "^7.2.1",
|
|
93
93
|
"eslint-plugin-unused-imports": "^4.4.1",
|
|
94
|
-
"globals": "^17.
|
|
95
|
-
"jsdom": "^
|
|
94
|
+
"globals": "^17.4.0",
|
|
95
|
+
"jsdom": "^29.0.1",
|
|
96
96
|
"prettier": "^3.8.1",
|
|
97
97
|
"rimraf": "^6.1.3",
|
|
98
|
-
"typescript": "^
|
|
99
|
-
"typescript-eslint": "^8.
|
|
100
|
-
"vitest": "^4.
|
|
98
|
+
"typescript": "^6.0.2",
|
|
99
|
+
"typescript-eslint": "^8.57.2",
|
|
100
|
+
"vitest": "^4.1.1"
|
|
101
101
|
},
|
|
102
102
|
"release": {
|
|
103
103
|
"branches": [
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"@semantic-release/github"
|
|
111
111
|
]
|
|
112
112
|
},
|
|
113
|
-
"packageManager": "yarn@4.
|
|
113
|
+
"packageManager": "yarn@4.13.0"
|
|
114
114
|
}
|