Skip to content

Commit fe8e86f

Browse files
authored
Allow use of raw.githubusercontent.com links (SchemaStore#4724)
1 parent 5b384df commit fe8e86f

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

cli.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ const SchemaValidation = /** @type {SchemaValidationJson} */ (
6262
const SchemaDir = './src/schemas/json'
6363
const TestPositiveDir = './src/test'
6464
const TestNegativeDir = './src/negative_test'
65-
const UrlSchemaStore = 'https://json.schemastore.org/'
65+
const SchemaStoreUrls = /** @type {const} */ ([
66+
'https://json.schemastore.org/',
67+
'https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/',
68+
])
6669
const [SchemasToBeTested, FoldersPositiveTest, FoldersNegativeTest] = (
6770
await Promise.all([
6871
fs.readdir(SchemaDir),
@@ -230,9 +233,11 @@ async function forEachFile(/** @type {ForEachTestFile} */ obj) {
230233
const schemaFile = await toFile(schemaPath)
231234
if (obj.actionName) {
232235
if (process.env.CI) {
233-
console.info(`Running "${obj.actionName}" on file "${schemaFile.path}"`)
236+
console.info(
237+
`Running "${obj.actionName}" on file "./${schemaFile.path}"`,
238+
)
234239
} else {
235-
spinner.text = `Running "${obj.actionName}" on file "${schemaFile.path}"`
240+
spinner.text = `Running "${obj.actionName}" on file "./${schemaFile.path}"`
236241
}
237242
}
238243
const data = await obj?.onSchemaFile?.(schemaFile, { spinner })
@@ -832,7 +837,12 @@ async function taskMaintenance() {
832837
{
833838
console.info(`===== BROKEN SCHEMAS =====`)
834839
forEachCatalogUrl((url) => {
835-
if (url.startsWith(UrlSchemaStore)) return
840+
if (
841+
url.startsWith(SchemaStoreUrls[0]) ||
842+
url.startsWith(SchemaStoreUrls[1])
843+
) {
844+
return
845+
}
836846

837847
fetch(url)
838848
.then(async (res) => {
@@ -1105,11 +1115,14 @@ async function assertCatalogJsonLocalURLsAreOneToOne() {
11051115
{
11061116
await forEachCatalogUrl((/** @type {string} */ catalogUrl) => {
11071117
// Skip external schemas.
1108-
if (!catalogUrl.startsWith(UrlSchemaStore)) {
1118+
if (
1119+
!catalogUrl.startsWith(SchemaStoreUrls[0]) &&
1120+
!catalogUrl.startsWith(SchemaStoreUrls[1])
1121+
) {
11091122
return
11101123
}
11111124

1112-
const filename = new URL(catalogUrl).pathname.slice(1)
1125+
const filename = path.basename(new URL(catalogUrl).pathname)
11131126

11141127
// Check that local URLs end in .json
11151128
if (!filename.endsWith('.json')) {
@@ -1136,8 +1149,11 @@ async function assertCatalogJsonLocalURLsAreOneToOne() {
11361149
const /** @type {string[]} */ allCatalogLocalJsonFiles = []
11371150

11381151
await forEachCatalogUrl((catalogUrl) => {
1139-
if (catalogUrl.startsWith(UrlSchemaStore)) {
1140-
const filename = new URL(catalogUrl).pathname.slice(1)
1152+
if (
1153+
catalogUrl.startsWith(SchemaStoreUrls[0]) ||
1154+
catalogUrl.startsWith(SchemaStoreUrls[1])
1155+
) {
1156+
const filename = path.basename(new URL(catalogUrl).pathname)
11411157
allCatalogLocalJsonFiles.push(filename)
11421158
}
11431159
})
@@ -1154,7 +1170,9 @@ async function assertCatalogJsonLocalURLsAreOneToOne() {
11541170
if (!allCatalogLocalJsonFiles.includes(schemaName)) {
11551171
printErrorAndExit(new Error(), [
11561172
`Expected schema file "${schemaName}" to have a corresponding entry in the catalog file "${CatalogFile}"`,
1157-
`Expected to find entry with "url" of "${UrlSchemaStore}${schemaName}"`,
1173+
`Expected to find entry with "url" that is one of:`,
1174+
` - "${SchemaStoreUrls[0]}${schemaName}"`,
1175+
` - "${SchemaStoreUrls[1]}${schemaName}"`,
11581176
`If this is intentional, ignore this error by appending to the property "missingCatalogUrl" in file "${SchemaValidationFile}"`,
11591177
])
11601178
}
@@ -1641,7 +1659,8 @@ async function printSimpleStatistics() {
16411659
let countScanURLInternal = 0
16421660

16431661
await forEachCatalogUrl((catalogUrl) => {
1644-
catalogUrl.startsWith(UrlSchemaStore)
1662+
catalogUrl.startsWith(SchemaStoreUrls[0]) ||
1663+
catalogUrl.startsWith(SchemaStoreUrls[1])
16451664
? countScanURLInternal++
16461665
: countScanURLExternal++
16471666
})

src/api/json/catalog.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@
853853
"name": "partial-black.json",
854854
"description": "black, a Python formatter",
855855
"fileMatch": [],
856-
"url": "https://json.schemastore.org/partial-black.json"
856+
"url": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/partial-black.json"
857857
},
858858
{
859859
"name": "bozr.suite.json",
@@ -1094,7 +1094,7 @@
10941094
"name": "cibuildwheel",
10951095
"description": "cibuildwheel, a Python redistributable wheel builder",
10961096
"fileMatch": ["cibuildwheel.toml", ".cibuildwheel.toml"],
1097-
"url": "https://json.schemastore.org/cibuildwheel.json"
1097+
"url": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/cibuildwheel.json"
10981098
},
10991099
{
11001100
"name": "CityJSON",
@@ -4670,7 +4670,7 @@
46704670
"name": "PyProject",
46714671
"description": "Python project metadata and configuration",
46724672
"fileMatch": ["pyproject.toml"],
4673-
"url": "https://json.schemastore.org/pyproject.json"
4673+
"url": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/pyproject.json"
46744674
},
46754675
{
46764676
"name": "Pyright",
@@ -4681,7 +4681,7 @@
46814681
{
46824682
"name": "pytest",
46834683
"description": "pytest configuration",
4684-
"url": "https://json.schemastore.org/partial-pytest.json"
4684+
"url": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/partial-pytest.json"
46854685
},
46864686
{
46874687
"name": "Qgoda",
@@ -5769,7 +5769,7 @@
57695769
"name": "uv",
57705770
"description": "uv, a fast Python package installer",
57715771
"fileMatch": ["uv.toml"],
5772-
"url": "https://json.schemastore.org/uv.json"
5772+
"url": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/uv.json"
57735773
},
57745774
{
57755775
"name": "Vector",
@@ -6312,7 +6312,7 @@
63126312
"name": "Hatch",
63136313
"description": "Python package build tool",
63146314
"fileMatch": ["hatch.toml"],
6315-
"url": "https://json.schemastore.org/hatch.json"
6315+
"url": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/hatch.json"
63166316
},
63176317
{
63186318
"name": "helmfile",
@@ -8020,7 +8020,7 @@
80208020
"name": "Python script metadata",
80218021
"description": "Metadata of a Python script, as defined by PEP 723",
80228022
"fileMatch": [],
8023-
"url": "https://json.schemastore.org/pep-723.json"
8023+
"url": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/pep-723.json"
80248024
},
80258025
{
80268026
"name": "vtcfg",

0 commit comments

Comments
 (0)