Skip to content

Commit 2916124

Browse files
committed
fix(resolve): if timeout is set, check for abort controller existence
1 parent 8e0964a commit 2916124

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

.claude/settings.local.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"permissions": {
3-
"allow": ["Bash(npx vitest:*)", "Bash(bash:*)", "Bash(node test-debug.js:*)"]
3+
"allow": [
4+
"Bash(npx vitest:*)",
5+
"Bash(bash:*)",
6+
"Bash(node test-debug.js:*)",
7+
"WebFetch(domain:github.com)"
8+
]
49
},
510
"enableAllProjectMcpServers": false
611
}

lib/resolvers/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async function download<S extends object = JSONSchema>(
121121
async function get<S extends object = JSONSchema>(u: RequestInfo | URL, httpOptions: HTTPResolverOptions<S>) {
122122
let controller: any;
123123
let timeoutId: any;
124-
if (httpOptions.timeout) {
124+
if (httpOptions.timeout && typeof AbortController !== "undefined") {
125125
controller = new AbortController();
126126
timeoutId = setTimeout(() => controller.abort(), httpOptions.timeout);
127127
}

test/specs/resolvers/resolvers.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,64 @@ describe("options.resolve", () => {
298298
properties: { test: { type: "string" } },
299299
});
300300
});
301+
302+
it("should properly resolve a remote schema", async () => {
303+
const mockHttpResolver = {
304+
order: 200,
305+
canRead: true,
306+
safeUrlResolver: false,
307+
read() {
308+
return {
309+
type: "object",
310+
properties: {
311+
firstName: {
312+
type: "string",
313+
},
314+
},
315+
};
316+
},
317+
};
318+
319+
const schema = await $RefParser.dereference(
320+
{
321+
type: "object",
322+
required: ["firstName"],
323+
properties: {
324+
firstName: {
325+
$ref: "#/$defs/externalModel/properties/firstName",
326+
},
327+
},
328+
$defs: {
329+
externalModel: {
330+
$ref: "http://localhost:5000/myModel",
331+
},
332+
},
333+
},
334+
{
335+
resolve: {
336+
http: mockHttpResolver,
337+
},
338+
} as ParserOptions,
339+
);
340+
341+
expect(schema).to.deep.equal({
342+
type: "object",
343+
required: ["firstName"],
344+
properties: {
345+
firstName: {
346+
type: "string",
347+
},
348+
},
349+
$defs: {
350+
externalModel: {
351+
type: "object",
352+
properties: {
353+
firstName: {
354+
type: "string",
355+
},
356+
},
357+
},
358+
},
359+
});
360+
});
301361
});

0 commit comments

Comments
 (0)