Skip to content

Commit c457625

Browse files
committed
feat: fix validate
1 parent afaec31 commit c457625

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

bun.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@types/react-dom": "^19.0.4",
2121
"@vitejs/plugin-react-swc": "^3.8.0",
2222
"ajv": "^8.12.0",
23+
"ajv-formats": "^2.1.1",
2324
"autoprefixer": "^10.4.21",
2425
"eslint": "^9.22.0",
2526
"eslint-plugin-react-hooks": "^5.2.0",
@@ -250,6 +251,8 @@
250251

251252
"ajv": ["ajv@8.17.1", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g=="],
252253

254+
"ajv-formats": ["ajv-formats@2.1.1", "", { "dependencies": { "ajv": "^8.0.0" } }, "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA=="],
255+
253256
"ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
254257

255258
"argparse": ["argparse@2.0.1", "", {}, "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@types/react-dom": "^19.0.4",
2828
"@vitejs/plugin-react-swc": "^3.8.0",
2929
"ajv": "^8.12.0",
30+
"ajv-formats": "^2.1.1",
3031
"autoprefixer": "^10.4.21",
3132
"eslint": "^9.22.0",
3233
"eslint-plugin-react-hooks": "^5.2.0",

scripts/validate.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { fileURLToPath } from 'url';
44
import Ajv from 'ajv';
5+
import addFormats from 'ajv-formats';
56

67
// Get directory name in ES modules
78
const __filename = fileURLToPath(import.meta.url);
@@ -20,8 +21,8 @@ const toolSchema = {
2021
description: { type: 'string', minLength: 10 },
2122
link: {
2223
type: 'string',
23-
format: 'uri',
24-
pattern: '^https?://'
24+
// Use pattern instead of format for URL validation
25+
pattern: '^https?://[\\w.-]+(\\.[\\w.-]+)+([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?$'
2526
},
2627
tags: {
2728
type: 'array',
@@ -34,6 +35,8 @@ const toolSchema = {
3435

3536
// Initialize Ajv
3637
const ajv = new Ajv({ allErrors: true });
38+
// Add format support (optional, since we're using pattern)
39+
addFormats(ajv);
3740
const validate = ajv.compile(toolSchema);
3841

3942
// Function to validate a JSON file
@@ -43,6 +46,13 @@ function validateJsonFile(filePath) {
4346
const fileContent = fs.readFileSync(filePath, 'utf8');
4447
const data = JSON.parse(fileContent);
4548

49+
// Basic URL validation (as a fallback)
50+
if (!data.link.startsWith('http://') && !data.link.startsWith('https://')) {
51+
console.error(`\x1b[31m❌ Validation failed for ${path.basename(filePath)}:\x1b[0m`);
52+
console.error(` - /link must start with http:// or https://`);
53+
return false;
54+
}
55+
4656
// Validate against schema
4757
const valid = validate(data);
4858

0 commit comments

Comments
 (0)