feat: Complete Issue #51 - Add outline mode to schema generation
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled

Implement comprehensive outline mode functionality for schema generation with:

• New CLI options: --mode outline, --depth parameter, --outfile alias
• Schema title format: "Schema from file.md" instead of "Schema for file.md"
• Metaschema extensions: x-markitect-outline-mode, x-markitect-outline-depth
• Depth control with validation (--depth must be >= 1)
• Parameter conflict detection and error handling
• Full backward compatibility with existing --max-depth option
• Comprehensive test coverage (10 new tests, all passing)
• Enhanced CLI help documentation with examples

Technical implementation:
- Extended SchemaGenerator.generate_schema_from_file() with mode/outline_depth parameters
- Updated CLI command with new options and parameter validation
- Maintained 100% compatibility with existing 493 tests
- Integrated with Issue #50 metaschema validation

Usage examples:
  markitect schema-generate --mode outline document.md
  markitect schema-generate --mode outline --depth 3 --outfile schema.json document.md

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-01 02:59:40 +02:00
parent 22008875d3
commit b5f510f9c7
3 changed files with 443 additions and 14 deletions

View File

@@ -28,13 +28,21 @@ class SchemaGenerator:
"""Initialize the schema generator."""
self.default_schema_url = "http://json-schema.org/draft-07/schema#"
def generate_schema_from_file(self, file_path: Path, max_depth: Optional[int] = None) -> Dict[str, Any]:
def generate_schema_from_file(
self,
file_path: Path,
max_depth: Optional[int] = None,
mode: Optional[str] = None,
outline_depth: Optional[int] = None
) -> Dict[str, Any]:
"""
Generate a JSON schema from a markdown file's AST structure.
Args:
file_path: Path to the markdown file
max_depth: Maximum heading depth to include (None = unlimited)
mode: Generation mode ('outline' for structure-focused schemas)
outline_depth: Depth limit for outline mode
Returns:
JSON schema as a dictionary
@@ -58,7 +66,7 @@ class SchemaGenerator:
structure_analysis = self._analyze_ast_structure(ast_tokens, max_depth)
# Generate the JSON schema
schema = self._create_json_schema(structure_analysis, file_path.name)
schema = self._create_json_schema(structure_analysis, file_path.name, mode=mode, outline_depth=outline_depth)
return schema
@@ -170,25 +178,42 @@ class SchemaGenerator:
return analysis
def _create_json_schema(self, analysis: Dict[str, Any], filename: str) -> Dict[str, Any]:
def _create_json_schema(
self,
analysis: Dict[str, Any],
filename: str,
mode: Optional[str] = None,
outline_depth: Optional[int] = None
) -> Dict[str, Any]:
"""
Create a JSON schema from structural analysis.
Args:
analysis: Structural analysis of the document
filename: Name of the source file
mode: Generation mode ('outline' for structure-focused schemas)
outline_depth: Depth limit for outline mode
Returns:
JSON schema dictionary
"""
# Determine title format based on mode
title_preposition = "from" if mode == "outline" else "for"
schema = {
"$schema": self.default_schema_url,
"type": "object",
"title": f"Schema for {filename}",
"title": f"Schema {title_preposition} {filename}",
"description": f"JSON schema describing the structure of {filename}",
"properties": {}
}
# Add metaschema extensions for outline mode
if mode == "outline":
schema["x-markitect-outline-mode"] = True
if outline_depth is not None:
schema["x-markitect-outline-depth"] = outline_depth
# Add heading structure
if analysis['headings']:
heading_properties = {}