Skip to content

Commit bc5308f

Browse files
authored
Update docs-checks.yml
Use generic validation to avoid issues with mintlify json schema
1 parent f548cf7 commit bc5308f

File tree

1 file changed

+77
-25
lines changed

1 file changed

+77
-25
lines changed

.github/workflows/docs-checks.yml

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,88 @@ jobs:
2424
with:
2525
node-version: '18'
2626

27-
- name: Validate docs.json against Mintlify schema
27+
- name: Validate docs.json structure
2828
run: |
29-
# Install ajv-cli for JSON schema validation
30-
npm install -g ajv-cli ajv-formats
29+
# First, validate it's valid JSON
30+
echo "Checking if docs.json is valid JSON..."
31+
cat docs.json | jq empty || (echo "docs.json is not valid JSON" && exit 1)
3132
32-
# Download Mintlify schema
33-
curl -o mintlify-schema.json https://leaves.mintlify.com/schema/docs.json
33+
# Now validate the Mintlify-specific structure
34+
echo "Validating Mintlify structure..."
35+
node -e "
36+
const fs = require('fs');
37+
const docs = JSON.parse(fs.readFileSync('docs.json', 'utf8'));
38+
const errors = [];
3439
35-
# Fix the broken regex patterns in the schema using | as delimiter
36-
# The schema has invalid escapes for colons and periods in regex patterns
37-
sed -i 's|\\\\:|:|g' mintlify-schema.json
38-
sed -i 's|\\\\\.|\\.|g' mintlify-schema.json
40+
// Check required top-level fields
41+
const required = ['name', 'theme', 'colors', 'navigation'];
42+
required.forEach(field => {
43+
if (!docs[field]) errors.push(\`Missing required field: \${field}\`);
44+
});
3945
40-
# Also fix the specific osano.com regex that's causing issues
41-
sed -i 's|"pattern":"\\^https\\\\:\\\\\\/\\\\\\/cmp\\\\.osano\\\\.com\\\\\\/"|"pattern":"^https://cmp\\.osano\\.com/"|' mintlify-schema.json
46+
// Validate theme
47+
const validThemes = ['mint', 'maple', 'palm', 'willow', 'linden', 'almond', 'aspen'];
48+
if (docs.theme && !validThemes.includes(docs.theme)) {
49+
errors.push(\`Invalid theme '\${docs.theme}'. Must be one of: \${validThemes.join(', ')}\`);
50+
}
4251
43-
# Validate docs.json
44-
echo "Validating docs.json against Mintlify schema..."
45-
if ajv validate -s mintlify-schema.json -d docs.json --strict=false --all-errors; then
46-
echo "docs.json valid - OK!"
47-
else
48-
echo "docs.json invalid"
49-
echo ""
50-
echo "Common issues to check:"
51-
echo "- theme must be one of: mint, maple, palm, willow, linden, almond, aspen"
52-
echo "- navigation structure must follow the schema"
53-
echo "- colors must be valid hex codes"
54-
echo "- all page references must be strings"
55-
exit 1
56-
fi
52+
// Validate colors
53+
if (docs.colors) {
54+
const hexRegex = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;
55+
if (!docs.colors.primary) errors.push('Missing required color: primary');
56+
57+
Object.entries(docs.colors).forEach(([name, color]) => {
58+
if (!hexRegex.test(color)) {
59+
errors.push(\`Invalid \${name} color '\${color}'. Must be a valid hex code.\`);
60+
}
61+
});
62+
}
63+
64+
// Validate navigation structure
65+
if (docs.navigation) {
66+
if (docs.navigation.tabs) {
67+
docs.navigation.tabs.forEach((tab, i) => {
68+
if (!tab.tab) errors.push(\`navigation.tabs[\${i}] missing required field: tab\`);
69+
70+
// Check for either pages or groups
71+
if (!tab.pages && !tab.groups) {
72+
errors.push(\`navigation.tabs[\${i}] must have either 'pages' or 'groups'\`);
73+
}
74+
75+
// Validate groups if present
76+
if (tab.groups) {
77+
tab.groups.forEach((group, j) => {
78+
if (!group.group) {
79+
errors.push(\`navigation.tabs[\${i}].groups[\${j}] missing required field: group\`);
80+
}
81+
if (!group.pages || !Array.isArray(group.pages)) {
82+
errors.push(\`navigation.tabs[\${i}].groups[\${j}] missing required field: pages (array)\`);
83+
}
84+
});
85+
}
86+
});
87+
} else if (!docs.navigation.pages && !docs.navigation.groups) {
88+
errors.push('navigation must have tabs, pages, or groups');
89+
}
90+
}
91+
92+
// Validate icon library if specified
93+
if (docs.icons?.library) {
94+
const validLibraries = ['fontawesome', 'lucide'];
95+
if (!validLibraries.includes(docs.icons.library)) {
96+
errors.push(\`Invalid icon library '\${docs.icons.library}'. Must be: \${validLibraries.join(' or ')}\`);
97+
}
98+
}
99+
100+
// Output results
101+
if (errors.length > 0) {
102+
console.error('invalid docs.json:');
103+
errors.forEach(err => console.error(' - ' + err));
104+
process.exit(1);
105+
} else {
106+
console.log('docs.json valid - OK!');
107+
}
108+
"
57109
58110
broken-links:
59111
name: Check Broken Links

0 commit comments

Comments
 (0)