@hey-api/json-schema-ref-parser 1.0.3 → 1.0.4
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/index.d.ts +6 -3
- package/dist/lib/index.js +18 -6
- package/dist/lib/resolve-external.js +1 -1
- package/dist/lib/resolvers/file.d.ts +3 -1
- package/dist/lib/resolvers/file.js +1 -1
- package/dist/lib/resolvers/url.d.ts +8 -4
- package/dist/lib/resolvers/url.js +9 -8
- package/lib/index.ts +21 -3
- package/lib/resolve-external.ts +1 -1
- package/lib/resolvers/file.ts +5 -1
- package/lib/resolvers/url.ts +19 -10
- package/package.json +1 -1
package/dist/lib/index.d.ts
CHANGED
|
@@ -37,8 +37,9 @@ export declare class $RefParser {
|
|
|
37
37
|
*
|
|
38
38
|
* @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
|
|
39
39
|
*/
|
|
40
|
-
bundle({ arrayBuffer, pathOrUrlOrSchema, resolvedInput, }: {
|
|
40
|
+
bundle({ arrayBuffer, fetch, pathOrUrlOrSchema, resolvedInput, }: {
|
|
41
41
|
arrayBuffer?: ArrayBuffer;
|
|
42
|
+
fetch?: RequestInit;
|
|
42
43
|
pathOrUrlOrSchema: JSONSchema | string | unknown;
|
|
43
44
|
resolvedInput?: ResolvedInput;
|
|
44
45
|
}): Promise<JSONSchema>;
|
|
@@ -51,7 +52,8 @@ export declare class $RefParser {
|
|
|
51
52
|
*
|
|
52
53
|
* @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
|
|
53
54
|
*/
|
|
54
|
-
dereference({ pathOrUrlOrSchema, }: {
|
|
55
|
+
dereference({ fetch, pathOrUrlOrSchema, }: {
|
|
56
|
+
fetch?: RequestInit;
|
|
55
57
|
pathOrUrlOrSchema: JSONSchema | string | unknown;
|
|
56
58
|
}): Promise<JSONSchema>;
|
|
57
59
|
/**
|
|
@@ -62,8 +64,9 @@ export declare class $RefParser {
|
|
|
62
64
|
* @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
|
|
63
65
|
* @returns - The returned promise resolves with the parsed JSON schema object.
|
|
64
66
|
*/
|
|
65
|
-
parse({ arrayBuffer, pathOrUrlOrSchema, resolvedInput: _resolvedInput, }: {
|
|
67
|
+
parse({ arrayBuffer, fetch, pathOrUrlOrSchema, resolvedInput: _resolvedInput, }: {
|
|
66
68
|
arrayBuffer?: ArrayBuffer;
|
|
69
|
+
fetch?: RequestInit;
|
|
67
70
|
pathOrUrlOrSchema: JSONSchema | string | unknown;
|
|
68
71
|
resolvedInput?: ResolvedInput;
|
|
69
72
|
}): Promise<{
|
package/dist/lib/index.js
CHANGED
|
@@ -118,8 +118,13 @@ class $RefParser {
|
|
|
118
118
|
*
|
|
119
119
|
* @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
|
|
120
120
|
*/
|
|
121
|
-
async bundle({ arrayBuffer, pathOrUrlOrSchema, resolvedInput, }) {
|
|
122
|
-
await this.parse({
|
|
121
|
+
async bundle({ arrayBuffer, fetch, pathOrUrlOrSchema, resolvedInput, }) {
|
|
122
|
+
await this.parse({
|
|
123
|
+
arrayBuffer,
|
|
124
|
+
fetch,
|
|
125
|
+
pathOrUrlOrSchema,
|
|
126
|
+
resolvedInput,
|
|
127
|
+
});
|
|
123
128
|
await (0, resolve_external_js_1.resolveExternal)(this, this.options);
|
|
124
129
|
const errors = errors_js_1.JSONParserErrorGroup.getParserErrors(this);
|
|
125
130
|
if (errors.length > 0) {
|
|
@@ -141,8 +146,11 @@ class $RefParser {
|
|
|
141
146
|
*
|
|
142
147
|
* @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
|
|
143
148
|
*/
|
|
144
|
-
async dereference({ pathOrUrlOrSchema, }) {
|
|
145
|
-
await this.parse({
|
|
149
|
+
async dereference({ fetch, pathOrUrlOrSchema, }) {
|
|
150
|
+
await this.parse({
|
|
151
|
+
fetch,
|
|
152
|
+
pathOrUrlOrSchema,
|
|
153
|
+
});
|
|
146
154
|
await (0, resolve_external_js_1.resolveExternal)(this, this.options);
|
|
147
155
|
const errors = errors_js_1.JSONParserErrorGroup.getParserErrors(this);
|
|
148
156
|
if (errors.length > 0) {
|
|
@@ -163,7 +171,7 @@ class $RefParser {
|
|
|
163
171
|
* @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
|
|
164
172
|
* @returns - The returned promise resolves with the parsed JSON schema object.
|
|
165
173
|
*/
|
|
166
|
-
async parse({ arrayBuffer, pathOrUrlOrSchema, resolvedInput: _resolvedInput, }) {
|
|
174
|
+
async parse({ arrayBuffer, fetch, pathOrUrlOrSchema, resolvedInput: _resolvedInput, }) {
|
|
167
175
|
const resolvedInput = _resolvedInput || (0, exports.getResolvedInput)({ pathOrUrlOrSchema });
|
|
168
176
|
const { path, type } = resolvedInput;
|
|
169
177
|
let { schema } = resolvedInput;
|
|
@@ -184,7 +192,11 @@ class $RefParser {
|
|
|
184
192
|
$refAdded.pathType = type;
|
|
185
193
|
try {
|
|
186
194
|
const resolver = type === 'file' ? file_js_1.fileResolver : url_js_1.urlResolver;
|
|
187
|
-
await resolver.handler(
|
|
195
|
+
await resolver.handler({
|
|
196
|
+
arrayBuffer,
|
|
197
|
+
fetch,
|
|
198
|
+
file,
|
|
199
|
+
});
|
|
188
200
|
const parseResult = await (0, parse_js_1.parseFile)(file, this.options);
|
|
189
201
|
$refAdded.value = parseResult.result;
|
|
190
202
|
schema = parseResult.result;
|
|
@@ -131,7 +131,7 @@ async function resolve$Ref($ref, path, $refs, options) {
|
|
|
131
131
|
let promises = [];
|
|
132
132
|
if (resolvedInput.type !== 'json') {
|
|
133
133
|
const resolver = resolvedInput.type === 'file' ? file_js_1.fileResolver : url_js_1.urlResolver;
|
|
134
|
-
await resolver.handler(file);
|
|
134
|
+
await resolver.handler({ file });
|
|
135
135
|
const parseResult = await (0, parse_js_1.parseFile)(file, options);
|
|
136
136
|
$refAdded.value = parseResult.result;
|
|
137
137
|
promises = crawl(parseResult.result, `${withoutHash}#`, $refs, options, new Set(), true);
|
|
@@ -42,7 +42,7 @@ const ono_1 = require("@jsdevtools/ono");
|
|
|
42
42
|
const url = __importStar(require("../util/url.js"));
|
|
43
43
|
const errors_js_1 = require("../util/errors.js");
|
|
44
44
|
exports.fileResolver = {
|
|
45
|
-
handler: async (file) => {
|
|
45
|
+
handler: async ({ file, }) => {
|
|
46
46
|
let path;
|
|
47
47
|
try {
|
|
48
48
|
path = url.toFileSystemPath(file.url);
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import type { FileInfo } from "../types/index.js";
|
|
2
|
-
export declare const sendRequest: ({
|
|
3
|
-
|
|
2
|
+
export declare const sendRequest: ({ fetchOptions, redirects, timeout, url, }: {
|
|
3
|
+
fetchOptions?: RequestInit;
|
|
4
4
|
redirects?: string[];
|
|
5
5
|
timeout?: number;
|
|
6
6
|
url: URL | string;
|
|
7
7
|
}) => Promise<{
|
|
8
|
-
|
|
8
|
+
fetchOptions?: RequestInit;
|
|
9
9
|
response: Response;
|
|
10
10
|
}>;
|
|
11
11
|
export declare const urlResolver: {
|
|
12
|
-
handler: (
|
|
12
|
+
handler: ({ arrayBuffer, fetch: _fetch, file, }: {
|
|
13
|
+
arrayBuffer?: ArrayBuffer;
|
|
14
|
+
fetch?: RequestInit;
|
|
15
|
+
file: FileInfo;
|
|
16
|
+
}) => Promise<void>;
|
|
13
17
|
};
|
|
@@ -4,7 +4,7 @@ exports.urlResolver = exports.sendRequest = void 0;
|
|
|
4
4
|
const ono_1 = require("@jsdevtools/ono");
|
|
5
5
|
const url_js_1 = require("../util/url.js");
|
|
6
6
|
const errors_js_1 = require("../util/errors.js");
|
|
7
|
-
const sendRequest = async ({
|
|
7
|
+
const sendRequest = async ({ fetchOptions, redirects = [], timeout = 60000, url, }) => {
|
|
8
8
|
url = new URL(url);
|
|
9
9
|
redirects.push(url.href);
|
|
10
10
|
const controller = new AbortController();
|
|
@@ -13,7 +13,7 @@ const sendRequest = async ({ init, redirects = [], timeout = 60000, url, }) => {
|
|
|
13
13
|
}, timeout);
|
|
14
14
|
const response = await fetch(url, {
|
|
15
15
|
signal: controller.signal,
|
|
16
|
-
...
|
|
16
|
+
...fetchOptions,
|
|
17
17
|
});
|
|
18
18
|
clearTimeout(timeoutId);
|
|
19
19
|
if (response.status >= 300 && response.status <= 399) {
|
|
@@ -24,29 +24,30 @@ const sendRequest = async ({ init, redirects = [], timeout = 60000, url, }) => {
|
|
|
24
24
|
throw (0, ono_1.ono)({ status: response.status }, `HTTP ${response.status} redirect with no location header`);
|
|
25
25
|
}
|
|
26
26
|
return (0, exports.sendRequest)({
|
|
27
|
-
|
|
27
|
+
fetchOptions,
|
|
28
28
|
redirects,
|
|
29
29
|
timeout,
|
|
30
30
|
url: (0, url_js_1.resolve)(url.href, response.headers.location),
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
return {
|
|
33
|
+
return { fetchOptions, response };
|
|
34
34
|
};
|
|
35
35
|
exports.sendRequest = sendRequest;
|
|
36
36
|
exports.urlResolver = {
|
|
37
|
-
handler: async (file,
|
|
37
|
+
handler: async ({ arrayBuffer, fetch: _fetch, file, }) => {
|
|
38
38
|
let data = arrayBuffer;
|
|
39
39
|
if (!data) {
|
|
40
40
|
try {
|
|
41
|
-
const {
|
|
42
|
-
|
|
41
|
+
const { fetchOptions, response } = await (0, exports.sendRequest)({
|
|
42
|
+
fetchOptions: {
|
|
43
43
|
method: 'GET',
|
|
44
|
+
..._fetch,
|
|
44
45
|
},
|
|
45
46
|
url: file.url,
|
|
46
47
|
});
|
|
47
48
|
if (response.status >= 400) {
|
|
48
49
|
// gracefully handle HEAD method not allowed
|
|
49
|
-
if (response.status !== 405 ||
|
|
50
|
+
if (response.status !== 405 || fetchOptions?.method !== 'HEAD') {
|
|
50
51
|
throw (0, ono_1.ono)({ status: response.status }, `HTTP ERROR ${response.status}`);
|
|
51
52
|
}
|
|
52
53
|
data = response.body ? await response.arrayBuffer() : new ArrayBuffer(0);
|
package/lib/index.ts
CHANGED
|
@@ -94,14 +94,21 @@ export class $RefParser {
|
|
|
94
94
|
*/
|
|
95
95
|
public async bundle({
|
|
96
96
|
arrayBuffer,
|
|
97
|
+
fetch,
|
|
97
98
|
pathOrUrlOrSchema,
|
|
98
99
|
resolvedInput,
|
|
99
100
|
}: {
|
|
100
101
|
arrayBuffer?: ArrayBuffer;
|
|
102
|
+
fetch?: RequestInit;
|
|
101
103
|
pathOrUrlOrSchema: JSONSchema | string | unknown;
|
|
102
104
|
resolvedInput?: ResolvedInput;
|
|
103
105
|
}): Promise<JSONSchema> {
|
|
104
|
-
await this.parse({
|
|
106
|
+
await this.parse({
|
|
107
|
+
arrayBuffer,
|
|
108
|
+
fetch,
|
|
109
|
+
pathOrUrlOrSchema,
|
|
110
|
+
resolvedInput,
|
|
111
|
+
});
|
|
105
112
|
await resolveExternal(this, this.options);
|
|
106
113
|
const errors = JSONParserErrorGroup.getParserErrors(this);
|
|
107
114
|
if (errors.length > 0) {
|
|
@@ -125,11 +132,16 @@ export class $RefParser {
|
|
|
125
132
|
* @param pathOrUrlOrSchema A JSON Schema object, or the file path or URL of a JSON Schema file.
|
|
126
133
|
*/
|
|
127
134
|
public async dereference({
|
|
135
|
+
fetch,
|
|
128
136
|
pathOrUrlOrSchema,
|
|
129
137
|
}: {
|
|
138
|
+
fetch?: RequestInit;
|
|
130
139
|
pathOrUrlOrSchema: JSONSchema | string | unknown;
|
|
131
140
|
}): Promise<JSONSchema> {
|
|
132
|
-
await this.parse({
|
|
141
|
+
await this.parse({
|
|
142
|
+
fetch,
|
|
143
|
+
pathOrUrlOrSchema,
|
|
144
|
+
});
|
|
133
145
|
await resolveExternal(this, this.options);
|
|
134
146
|
const errors = JSONParserErrorGroup.getParserErrors(this);
|
|
135
147
|
if (errors.length > 0) {
|
|
@@ -153,10 +165,12 @@ export class $RefParser {
|
|
|
153
165
|
*/
|
|
154
166
|
public async parse({
|
|
155
167
|
arrayBuffer,
|
|
168
|
+
fetch,
|
|
156
169
|
pathOrUrlOrSchema,
|
|
157
170
|
resolvedInput: _resolvedInput,
|
|
158
171
|
}: {
|
|
159
172
|
arrayBuffer?: ArrayBuffer;
|
|
173
|
+
fetch?: RequestInit;
|
|
160
174
|
pathOrUrlOrSchema: JSONSchema | string | unknown;
|
|
161
175
|
resolvedInput?: ResolvedInput;
|
|
162
176
|
}): Promise<{ schema: JSONSchema }> {
|
|
@@ -182,7 +196,11 @@ export class $RefParser {
|
|
|
182
196
|
$refAdded.pathType = type;
|
|
183
197
|
try {
|
|
184
198
|
const resolver = type === 'file' ? fileResolver : urlResolver;
|
|
185
|
-
await resolver.handler(
|
|
199
|
+
await resolver.handler({
|
|
200
|
+
arrayBuffer,
|
|
201
|
+
fetch,
|
|
202
|
+
file,
|
|
203
|
+
});
|
|
186
204
|
const parseResult = await parseFile(file, this.options);
|
|
187
205
|
$refAdded.value = parseResult.result;
|
|
188
206
|
schema = parseResult.result;
|
package/lib/resolve-external.ts
CHANGED
|
@@ -124,7 +124,7 @@ async function resolve$Ref<S extends object = JSONSchema>(
|
|
|
124
124
|
|
|
125
125
|
if (resolvedInput.type !== 'json') {
|
|
126
126
|
const resolver = resolvedInput.type === 'file' ? fileResolver : urlResolver;
|
|
127
|
-
await resolver.handler(file);
|
|
127
|
+
await resolver.handler({ file });
|
|
128
128
|
const parseResult = await parseFile(file, options);
|
|
129
129
|
$refAdded.value = parseResult.result;
|
|
130
130
|
promises = crawl(parseResult.result, `${withoutHash}#`, $refs, options, new Set(), true);
|
package/lib/resolvers/file.ts
CHANGED
|
@@ -5,7 +5,11 @@ import { ResolverError } from "../util/errors.js";
|
|
|
5
5
|
import type { FileInfo } from "../types/index.js";
|
|
6
6
|
|
|
7
7
|
export const fileResolver = {
|
|
8
|
-
handler: async (
|
|
8
|
+
handler: async ({
|
|
9
|
+
file,
|
|
10
|
+
}: {
|
|
11
|
+
file: FileInfo;
|
|
12
|
+
}): Promise<void> => {
|
|
9
13
|
let path: string | undefined;
|
|
10
14
|
|
|
11
15
|
try {
|
package/lib/resolvers/url.ts
CHANGED
|
@@ -4,17 +4,17 @@ import { ResolverError } from "../util/errors.js";
|
|
|
4
4
|
import type { FileInfo } from "../types/index.js";
|
|
5
5
|
|
|
6
6
|
export const sendRequest = async ({
|
|
7
|
-
|
|
7
|
+
fetchOptions,
|
|
8
8
|
redirects = [],
|
|
9
9
|
timeout = 60_000,
|
|
10
10
|
url,
|
|
11
11
|
}: {
|
|
12
|
-
|
|
12
|
+
fetchOptions?: RequestInit;
|
|
13
13
|
redirects?: string[];
|
|
14
14
|
timeout?: number;
|
|
15
15
|
url: URL | string;
|
|
16
16
|
}): Promise<{
|
|
17
|
-
|
|
17
|
+
fetchOptions?: RequestInit;
|
|
18
18
|
response: Response;
|
|
19
19
|
}> => {
|
|
20
20
|
url = new URL(url);
|
|
@@ -26,7 +26,7 @@ export const sendRequest = async ({
|
|
|
26
26
|
}, timeout);
|
|
27
27
|
const response = await fetch(url, {
|
|
28
28
|
signal: controller.signal,
|
|
29
|
-
...
|
|
29
|
+
...fetchOptions,
|
|
30
30
|
});
|
|
31
31
|
clearTimeout(timeoutId);
|
|
32
32
|
|
|
@@ -45,32 +45,41 @@ export const sendRequest = async ({
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
return sendRequest({
|
|
48
|
-
|
|
48
|
+
fetchOptions,
|
|
49
49
|
redirects,
|
|
50
50
|
timeout,
|
|
51
51
|
url: resolve(url.href, response.headers.location as string),
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
return {
|
|
55
|
+
return { fetchOptions, response };
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
export const urlResolver = {
|
|
59
|
-
handler: async (
|
|
59
|
+
handler: async ({
|
|
60
|
+
arrayBuffer,
|
|
61
|
+
fetch: _fetch,
|
|
62
|
+
file,
|
|
63
|
+
}: {
|
|
64
|
+
arrayBuffer?: ArrayBuffer;
|
|
65
|
+
fetch?: RequestInit;
|
|
66
|
+
file: FileInfo;
|
|
67
|
+
}): Promise<void> => {
|
|
60
68
|
let data = arrayBuffer;
|
|
61
69
|
|
|
62
70
|
if (!data) {
|
|
63
71
|
try {
|
|
64
|
-
const {
|
|
65
|
-
|
|
72
|
+
const { fetchOptions, response } = await sendRequest({
|
|
73
|
+
fetchOptions: {
|
|
66
74
|
method: 'GET',
|
|
75
|
+
..._fetch,
|
|
67
76
|
},
|
|
68
77
|
url: file.url,
|
|
69
78
|
});
|
|
70
79
|
|
|
71
80
|
if (response.status >= 400) {
|
|
72
81
|
// gracefully handle HEAD method not allowed
|
|
73
|
-
if (response.status !== 405 ||
|
|
82
|
+
if (response.status !== 405 || fetchOptions?.method !== 'HEAD') {
|
|
74
83
|
throw ono({ status: response.status }, `HTTP ERROR ${response.status}`);
|
|
75
84
|
}
|
|
76
85
|
|