SIGN IN SIGN UP
withastro / astro UNCLAIMED

The web framework for content-driven websites. ⭐️ Star to support our work!

0 0 125 TypeScript

fix(content): generate anyOf schema for file() loader to support top-level arrays (#16730)

* fix(content): generate anyOf schema for file() loader to support top-level arrays

The file() loader accepts both top-level array JSON files and record object
JSON files. Previously, generateJSONSchema always wrapped the item schema in
z.object({}).catchall() which produces a type:object JSON schema. When the
source file is a top-level array, VS Code reports validation errors because
the data shape doesn't match the generated schema.

Replace the object-only wrapping with a z.union of the array shape and the
object shape. This generates an anyOf in the output JSON schema, allowing
VS Code to validate array-shaped and object-shaped files correctly.

The $schema property is injected into the object branch only — top-level
array JSON files cannot reference an external schema property.

Fixes #16602

* test: update content intellisense test for file loader union schema

* chore: add changeset for file loader anyOf schema fix

* docs(changeset): reword to user-facing prose per astro guide
H
Harsh Agarwal committed
068d924402dced7670530774f36cca301f91e60c
Parent: 8f77583
Committed by GitHub <noreply@github.com> on 5/19/2026, 4:54:38 AM