Skip to content

Commit 604f7f8

Browse files
authored
feat: normalize schemastore URLs to use www.schemastore.org` (#424)
* feat: normalize schemastore URLs to use `www.schemastore.org` * Create two-years-jam.md
1 parent 207eac4 commit 604f7f8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.changeset/two-years-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-json-schema-validator": minor
3+
---
4+
5+
feat: normalize schemastore URLs to use `www.schemastore.org`

src/utils/schema.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function loadJsonInternal<T>(
4242
edit?: (json: unknown) => T,
4343
): null | T {
4444
if (jsonPath.startsWith("http://") || jsonPath.startsWith("https://")) {
45-
return loadJsonFromURL(jsonPath, context, edit);
45+
return loadJsonFromURL(normalizeSchemaUrl(jsonPath), context, edit);
4646
}
4747
if (jsonPath.startsWith("vscode://")) {
4848
let url = `https://raw.githubusercontent.com/ota-meshi/extract-vscode-schemas/main/resources/vscode/${jsonPath.slice(
@@ -78,6 +78,21 @@ function loadJsonInternal<T>(
7878
return edit ? edit(data) : data;
7979
}
8080

81+
/**
82+
* Normalize schema URL to use the official schemastore domain.
83+
*/
84+
function normalizeSchemaUrl(url: string): string {
85+
for (const prefix of [
86+
"https://json.schemastore.org/",
87+
"http://json.schemastore.org/",
88+
]) {
89+
if (url.startsWith(prefix)) {
90+
return `https://www.schemastore.org/${url.slice(prefix.length)}`;
91+
}
92+
}
93+
return url;
94+
}
95+
8196
/** remove empty `enum:` schema */
8297
function removeEmptyEnum(
8398
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore

0 commit comments

Comments
 (0)