diff --git a/.changeset/two-years-jam.md b/.changeset/two-years-jam.md new file mode 100644 index 00000000..001f7e02 --- /dev/null +++ b/.changeset/two-years-jam.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-json-schema-validator": minor +--- + +feat: normalize schemastore URLs to use `www.schemastore.org` diff --git a/src/utils/schema.ts b/src/utils/schema.ts index 04c67874..cdb53543 100644 --- a/src/utils/schema.ts +++ b/src/utils/schema.ts @@ -42,7 +42,7 @@ function loadJsonInternal( 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( @@ -78,6 +78,21 @@ function loadJsonInternal( 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