Add JSON Schema validation for front matter with taxonomy enum validation#991
Add JSON Schema validation for front matter with taxonomy enum validation#991
Conversation
Co-authored-by: estruyf <2900833+estruyf@users.noreply.github.com>
Co-authored-by: estruyf <2900833+estruyf@users.noreply.github.com>
Co-authored-by: estruyf <2900833+estruyf@users.noreply.github.com>
|
@copilot when you are using tags or categories, there should also be validation on the available tags and categories you can pick from. Show a warning when a tag/category is used that is not in the known list. |
…n values Co-authored-by: estruyf <2900833+estruyf@users.noreply.github.com>
Implemented in commit 5de91cf. The schema generator now:
When users type unknown tags/categories, they'll see inline warnings like: "Field 'tags/0' must be one of: javascript, typescript, react" |
|
@copilot can we make use of https://zod.dev/ for this feature? |
We could switch to Zod, but it would require significant refactoring since the current implementation is built around JSON Schema with AJV (already a dependency). Current approach benefits:
Switching to Zod would require:
Since the current implementation is working correctly and provides the needed validation, I'd suggest keeping AJV for this feature. If Zod is preferred for the codebase, it could be a separate refactoring effort. Would you like me to proceed with the current AJV implementation or refactor to use Zod? |
PR Details
Description
Implements automatic validation of YAML front matter against content type definitions using JSON Schema. When a markdown file is opened, its front matter is validated in real-time and errors are surfaced as inline warnings.
Implementation
ContentTypeSchemaGenerator - Converts content type field definitions to JSON Schema
FrontMatterValidator - Validates front matter using AJV
StatusListener integration - Adds schema validation to existing diagnostics
---delimiters)missingPropertyparameterExample
Given a content type:
Invalid front matter triggers inline warnings:
Taxonomy Validation
The validation now checks tags, categories, and custom taxonomy fields against known values:
TaxonomyHelper.get(TaxonomyType.Tag)TaxonomyHelper.get(TaxonomyType.Category)This helps catch typos early, enforces consistency, and ensures only valid taxonomy values are used across content.
Known Limitations
Field location detection uses string matching (
fieldName:) within front matter section. More precise location reporting would require YAML AST parsing.Related Issue
Fixes enhancement request for schema validation of front matter.
Motivation and Context
Content type definitions specify structure but weren't enforced at edit-time. This creates a tight feedback loop by validating as users type, catching errors before they cause issues downstream. The addition of taxonomy validation prevents inconsistent tag/category usage and catches typos immediately.
How Has This Been Tested
Types of changes
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.