mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
65692fa7b5
* 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>
1.3 KiB
1.3 KiB
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:
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:
// src/content/test/entry.json
{
+ "$schema": "../../../.astro/collections/test.schema.json",
"test": "test"
}
Alternatively, you can set this in your VSCode json.schemas
settings:
"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, so you may wish to consult these limitations before enabling the experimental flag.