Expand description
Positioned, reusable schema validation — the single semantic-diagnostics
authority for a parsed Schema.
§Why this lives in forgedb-parser
Schema validation logically belongs next to the diagnostic vocabulary
(ValidationError / Position) in [forgedb-validation], and epic #173
(WS2b) originally proposed extending that crate. But forgedb-validation
cannot see the Schema AST: forgedb-parser already depends on
forgedb-validation (for Position/ValidationError), so a reverse
dependency would be a cycle. The AST lives here, so the walk that validates
it lives here too — reusing the diagnostic types and naming predicates from
forgedb-validation. The split is: validation crate = diagnostic types +
reusable predicates; parser = the AST and the walk that applies them.
§The single authority
validate_schema is the one implementation of ForgeDB’s schema-level
semantic rules. It is consumed by:
- the parser itself (
crate::Parser::parseruns it fail-fast to preserve itsResult<Schema, String>contract), and - the CLI
forgedb validatecommand and the LSP, which call it directly on aParser::parse_unvalidatedAST to surface all diagnostics with positions instead of just the first.
Everything it reports is a property of the assembled Schema (names,
duplicates, cross-references, type constraints). Purely syntactic errors
(unexpected tokens, malformed directives, empty models, composite-index
arity) remain fatal in the parser’s structural pass and never reach here.
Callers that also need filesystem checks (component-file existence) or advisory lints (no id / no timestamp) layer those on top — those are not pure-schema diagnostics and stay in the CLI.
Functions§
- collect_
naming_ errors - Naming-convention diagnostics: PascalCase model/struct/enum names and enum variants, snake_case field names.
- collect_
structure_ errors - Structural / reference diagnostics: duplicate names (model/struct/enum, fields within a container, enum variants), relation targets resolve, struct/enum type references resolve, structs contain only fixed-size types, and composite-index / projection field references exist.
- validate_
schema - Run the full positioned semantic validation of a parsed schema and return every diagnostic (naming + structural). Does not fail fast.