|
| 1 | +# Copilot Instructions for SchemaStore |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +SchemaStore is the world's largest collection of independent JSON schemas. This repository contains JSON Schema files that validate popular configuration files and data formats. The schemas are used by IDEs and language servers to provide autocompletion and validation. |
| 6 | + |
| 7 | +## Repository Structure |
| 8 | + |
| 9 | +- `src/schemas/json/` - JSON Schema files |
| 10 | +- `src/test/` - Positive test files (JSON, YAML, TOML) |
| 11 | +- `src/negative_test/` - Negative test files |
| 12 | +- `src/api/json/catalog.json` - Schema catalog mapping schemas to file patterns |
| 13 | +- `src/schema-validation.jsonc` - Validation configuration |
| 14 | +- `cli.js` - Main CLI tool for schema operations |
| 15 | + |
| 16 | +## Key Guidelines |
| 17 | + |
| 18 | +### Schema Authoring |
| 19 | + |
| 20 | +1. **Use draft-07**: Prefer `draft-07` JSON Schema version for best IDE/language server support |
| 21 | +2. **Minimal Changes**: Make surgical, precise changes to existing schemas |
| 22 | +3. **No Over-Constraint**: |
| 23 | + - Avoid overly restrictive constraints that may break with new versions |
| 24 | + - Be cautious with `additionalProperties: false` and exhaustive enums |
| 25 | + - Don't add complex regex patterns for cron strings, URLs, or DSLs |
| 26 | +4. **Document Everything**: |
| 27 | + - Use `description` fields with format: `<description>\n<url>` |
| 28 | + - Mark undocumented features with `UNDOCUMENTED.` prefix in description |
| 29 | + - Mark deprecated features with `DEPRECATED.` prefix in description |
| 30 | +5. **Test Coverage**: Always add positive test files in `src/test/<schemaName>/` |
| 31 | +6. **API Compatibility**: Preserve schema names and paths to avoid breaking changes |
| 32 | + |
| 33 | +### Schema Validation |
| 34 | + |
| 35 | +**Always validate changes before committing:** |
| 36 | + |
| 37 | +```bash |
| 38 | +# Validate a specific schema |
| 39 | +node ./cli.js check --schema-name=<schemaName.json> |
| 40 | + |
| 41 | +# Validate all schemas (slower) |
| 42 | +node ./cli.js check |
| 43 | +``` |
| 44 | + |
| 45 | +### Catalog.json Guidelines |
| 46 | + |
| 47 | +1. **File Matching**: Add appropriate `fileMatch` patterns for auto-detection |
| 48 | +2. **Avoid Generic Patterns**: Don't use generic patterns like `config.toml` or `settings.json` |
| 49 | +3. **Alphabetical Order**: Register schemas alphabetically in catalog.json |
| 50 | +4. **Required Fields**: Include `name`, `description`, `fileMatch`, and `url` |
| 51 | + |
| 52 | +### Code Style |
| 53 | + |
| 54 | +- Use Prettier for formatting: `npm run prettier:fix` |
| 55 | +- Follow existing patterns in the codebase |
| 56 | +- Don't add comments unless they match existing style |
| 57 | + |
| 58 | +### Creating New Schemas |
| 59 | + |
| 60 | +Use the CLI tool to scaffold new schemas: |
| 61 | + |
| 62 | +```bash |
| 63 | +node cli.js new-schema |
| 64 | +``` |
| 65 | + |
| 66 | +This will: |
| 67 | + |
| 68 | +- Create schema file in `src/schemas/json/<schemaName>.json` |
| 69 | +- Create test file in `src/test/<schemaName>/<schemaName>.json` |
| 70 | +- Provide catalog.json entry to add manually |
| 71 | + |
| 72 | +### External References |
| 73 | + |
| 74 | +When adding `$ref` to another schema in this repository: |
| 75 | + |
| 76 | +- Both schemas must use the same draft version |
| 77 | +- Referenced schema must have proper `$id` field |
| 78 | +- Add entry to `src/schema-validation.jsonc` under `externalSchema` |
| 79 | + |
| 80 | +### Common Validation Issues |
| 81 | + |
| 82 | +- **Strict mode errors**: Add schema to `ajvNotStrictMode` array in `schema-validation.jsonc` |
| 83 | +- **Unknown format/keyword**: Add schema to `options` object in `schema-validation.jsonc` |
| 84 | +- **High schema version**: Add schema to `highSchemaVersion` array |
| 85 | + |
| 86 | +## What NOT to Do |
| 87 | + |
| 88 | +- ❌ Don't remove working code or tests unrelated to your changes |
| 89 | +- ❌ Don't add `additionalProperties: false` without careful consideration |
| 90 | +- ❌ Don't use exhaustive enums without `"type": "string"` fallback |
| 91 | +- ❌ Don't add overly complex regex patterns |
| 92 | +- ❌ Don't modify schemas without adding/updating tests |
| 93 | +- ❌ Don't commit without running validation |
| 94 | +- ❌ Don't use generic fileMatch patterns in catalog.json |
| 95 | + |
| 96 | +## Testing Workflow |
| 97 | + |
| 98 | +1. Make changes to schema file |
| 99 | +2. Add/update test files in `src/test/<schemaName>/` |
| 100 | +3. Run validation: `node ./cli.js check --schema-name=<schemaName.json>` |
| 101 | +4. Run Prettier: `npm run prettier:fix` |
| 102 | +5. Commit changes |
| 103 | + |
| 104 | +## Additional Resources |
| 105 | + |
| 106 | +- Full contributing guide: [CONTRIBUTING.md](../CONTRIBUTING.md) |
| 107 | +- Schema validation details: See "Schema Validation" section in CONTRIBUTING.md |
| 108 | +- Language server compatibility: See "Compatible Language Servers and Tools" section |
| 109 | +- Best practices: See "Schema Authoring" section in CONTRIBUTING.md |
| 110 | + |
| 111 | +## Quick Reference |
| 112 | + |
| 113 | +**Add new schema:** |
| 114 | + |
| 115 | +```bash |
| 116 | +node cli.js new-schema |
| 117 | +``` |
| 118 | + |
| 119 | +**Validate schema:** |
| 120 | + |
| 121 | +```bash |
| 122 | +node ./cli.js check --schema-name=<schemaName.json> |
| 123 | +``` |
| 124 | + |
| 125 | +**Format code:** |
| 126 | + |
| 127 | +```bash |
| 128 | +npm run prettier:fix |
| 129 | +``` |
| 130 | + |
| 131 | +**Run type checking:** |
| 132 | + |
| 133 | +```bash |
| 134 | +npm run typecheck |
| 135 | +``` |
| 136 | + |
| 137 | +**Lint CLI:** |
| 138 | + |
| 139 | +```bash |
| 140 | +npm run eslint:fix |
| 141 | +``` |
0 commit comments