Skip to content

Add JSON Schema generation for Flint ChartAssemblyInput - #83

Draft
yelper wants to merge 1 commit into
microsoft:mainfrom
yelper:dev/alsarika/investigate-json-schema-generation
Draft

Add JSON Schema generation for Flint ChartAssemblyInput#83
yelper wants to merge 1 commit into
microsoft:mainfrom
yelper:dev/alsarika/investigate-json-schema-generation

Conversation

@yelper

@yelper yelper commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a generation script (scripts/gen-json-schema.ts) that produces JSON Schema files describing the full permitted ChartAssemblyInput shape. These schemas enable LLM structured-output validation, IDE autocomplete for JSON-based workflows, and runtime validation.

This PR is just for feedback for the implementation; we'd need to wire it up to the build scripts and publicize it somewhere on the docs site.

If we actually wanted to do versioning (i.e., the $schema determines how Flint parses the given spec), then we'd need to publish these schemas in a well-known place. For Microsoft, this would be in the under the "http://developer.microsoft.com/json-schemas" URI, which is governed by https://github.com/microsoft/json-schemas/.

Output

Five schema files in docs/schema/:

File Scope Chart types
flint-input.schema.json Universal (all backends) 18
flint-input-vegalite.schema.json Vega-Lite 35
flint-input-echarts.schema.json ECharts 37
flint-input-chartjs.schema.json Chart.js 21
flint-input-plotly.schema.json Plotly 38

Schema features

  • Full ChartAssemblyInput structure (data, semantic_types, chart_spec, options, field_display_names)
  • chartType enum - precise per backend; universal schema only includes types common to all four backends
  • Per-chart-type conditional sub-schemas (allOf + if/then) constraining valid encoding channel names and typed chartProperties
  • AssembleOptions with all layout tuning parameters fully typed
  • Semantic type enum (40+ registered types) + SemanticAnnotation object form
  • Root $ + schema property allowed for standalone .json files
  • JSON Schema Draft 2020-12

Usage

npm run gen:schema

Example usage (by users)

Enables per-chart autocomplete suggestions / validation.

image

Open questions

  • Should the generated schemas be checked in (current approach) or only produced in CI?
  • Any chart properties missing from the conditional sub-schemas?
  • Should we require encodings per-chart type? For example, it doesn't make sense to choose "Bar chart" but then not chose both and x + y encoding.
  • Should we wire gen:schema into a pre-commit or CI check to keep schemas in sync?

Introduce scripts/gen-json-schema.ts that produces 5 JSON Schema files in
docs/schema/:
- flint-input.schema.json (universal — 18 chart types common to all backends)
- flint-input-vegalite.schema.json (35 chart types)
- flint-input-echarts.schema.json (37 chart types)
- flint-input-chartjs.schema.json (21 chart types)
- flint-input-plotly.schema.json (38 chart types)

Each schema includes per-chart-type conditional sub-schemas (if/then) that
constrain valid encoding channels and typed chartProperties. The schemas
use Draft 2020-12 and allow a root \\\ property for standalone files.

Run via: npm run gen:schema

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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