0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-13 22:11:20 -05:00
astro/.changeset/slow-items-heal.md
Alexander Niebuhr 65692fa7b5
feat: experimental content collection JSON schemas (#10145)
* feat: experimental content collection JSON schemas

* solves review comments

* solves review comments

* updates changeset

* updates path

* fixes formatting

* removes unrelated changes

* adds test

* fixes lockfile

* chore: fixes package name

* improves code branching depth

* resolves docs comments

Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>

* Update packages/astro/src/content/types-generator.ts

* Update .changeset/slow-items-heal.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

---------

Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2024-03-08 10:54:51 +00:00

44 lines
1.3 KiB
Markdown

---
"astro": minor
---
Adds experimental JSON Schema support for content collections.
This feature will auto-generate a JSON Schema for content collections of `type: 'data'` which can be used as the `$schema` value for TypeScript-style autocompletion/hints in tools like VSCode.
To enable this feature, add the experimental flag:
```diff
import { defineConfig } from 'astro/config';
export default defineConfig({
experimental: {
+ contentCollectionJsonSchema: true
}
});
```
This experimental implementation requires you to manually reference the schema in each data entry file of the collection:
```diff
// src/content/test/entry.json
{
+ "$schema": "../../../.astro/collections/test.schema.json",
"test": "test"
}
```
Alternatively, you can set this in your [VSCode `json.schemas` settings](https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings):
```diff
"json.schemas": [
{
"fileMatch": [
"/src/content/test/**"
],
"url": "../../../.astro/collections/test.schema.json"
}
]
```
Note that this initial implementation uses a library with [known issues for advanced Zod schemas](https://github.com/StefanTerdell/zod-to-json-schema#known-issues), so you may wish to consult these limitations before enabling the experimental flag.