Skip to content

Nested Schema Validation & Type mismatch check#729

Open
AbhinRustagi wants to merge 14 commits into
mainfrom
ar-schema-validation
Open

Nested Schema Validation & Type mismatch check#729
AbhinRustagi wants to merge 14 commits into
mainfrom
ar-schema-validation

Conversation

@AbhinRustagi

@AbhinRustagi AbhinRustagi commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What

Closes TH-2076

Add schema-based type/enum validation for component props during materialization. Previously, the materializer only checked for missing required fields and unknown components. Values passed to a component were never validated against the declared JSON Schema type. This fills that gap.

Changes

  • types.ts: Add ScalarParamType union ("string" | "number" | "boolean") and a schema?: unknown field on ParamDef to carry the raw JSON Schema fragment per parameter. Add "type-mismatch" to ValidationErrorCode.
  • parser.ts: Populate param.schema from the compiled schema during compileSchema, so every ParamDef carries its full JSON Schema fragment.
  • materialize.ts:
    • Introduce validateSchemaValue — a recursive JSON Schema validator that handles type: object (required keys, declared properties), type: array (single-schema items), and scalar leaf types/enums. Skips composite shapes ($ref, anyOf, oneOf, allOf), runtime AST nodes, and child ElementNodes (those validate as their own elements).
    • Add describeTypeMismatch and getScalarTypeInfo as scalar-leaf helpers.
    • Call validateSchemaValue for each positional argument after it's materialized, when the param carries a schema.
    • Extract pushValidationError helper to stop repeating statementId: ctx.currentStatementId at every call site.

Test Plan

  • Verified locally

Checklist

  • I linked a related issue, if applicable
  • I updated docs/README when needed
  • I considered backwards compatibility

@AbhinRustagi AbhinRustagi marked this pull request as ready for review July 9, 2026 04:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant