Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/quicktype-core/src/input/JSONSchemaInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ class Resolver {
return [schema, result[1]];
}

return schemaFetchError(base, virtualRef.address);
return schemaFetchError(base, virtualRef.toString());
}

public async resolveTopLevelRef(ref: Ref): Promise<[JSONSchema, Location]> {
Expand Down
36 changes: 36 additions & 0 deletions test/unit/missing-schema-path.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";

import {
FetchingJSONSchemaStore,
InputData,
JSONSchemaInput,
quicktype,
} from "quicktype-core";
import { expect, test } from "vitest";

// Regression test for issue #2812: shells such as PowerShell pass wildcard
// arguments through literally, so a schema wildcard with no matching file must
// report a normal missing-file error rather than an internal error.
test("missing JSON Schema paths report the fetch error", async () => {
const tempDir = fs.mkdtempSync(
path.join(os.tmpdir(), "quicktype-missing-schema-"),
);
const missingPath = path.join(tempDir, "*.json");

try {
const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());
await schemaInput.addSource({ name: "TopLevel", uris: [missingPath] });
const inputData = new InputData();
inputData.addInput(schemaInput);

await expect(
quicktype({ inputData, lang: "typescript" }),
).rejects.toThrow(
`Could not fetch schema #, referred to from ${missingPath}#`,
);
} finally {
fs.rmSync(tempDir, { recursive: true, force: true });
}
});
Loading