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
5 changes: 5 additions & 0 deletions .changeset/two-years-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-json-schema-validator": minor
---

feat: normalize schemastore URLs to use `www.schemastore.org`
17 changes: 16 additions & 1 deletion src/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function loadJsonInternal<T>(
edit?: (json: unknown) => T,
): null | T {
if (jsonPath.startsWith("http://") || jsonPath.startsWith("https://")) {
return loadJsonFromURL(jsonPath, context, edit);
return loadJsonFromURL(normalizeSchemaUrl(jsonPath), context, edit);
}
if (jsonPath.startsWith("vscode://")) {
let url = `https://raw.githubusercontent.com/ota-meshi/extract-vscode-schemas/main/resources/vscode/${jsonPath.slice(
Expand Down Expand Up @@ -78,6 +78,21 @@ function loadJsonInternal<T>(
return edit ? edit(data) : data;
}

/**
* Normalize schema URL to use the official schemastore domain.
*/
function normalizeSchemaUrl(url: string): string {
for (const prefix of [
"https://json.schemastore.org/",
"http://json.schemastore.org/",
]) {
if (url.startsWith(prefix)) {
return `https://www.schemastore.org/${url.slice(prefix.length)}`;
}
}
return url;
}

/** remove empty `enum:` schema */
function removeEmptyEnum(
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore
Expand Down
Loading