diff --git a/src/content/docs/en/guides/content-collections.mdx b/src/content/docs/en/guides/content-collections.mdx index d988a835b85ae..9a71dc2964fba 100644 --- a/src/content/docs/en/guides/content-collections.mdx +++ b/src/content/docs/en/guides/content-collections.mdx @@ -543,6 +543,37 @@ If you have an existing Astro project, such as a blog, that uses Markdown or MDX See how to convert a basic blog example from `src/pages/posts/` to `src/content/posts` in our [step-by-step tutorial](/en/tutorials/add-content-collections/) that uses the codebase from [the Build a Blog tutorial's finished project](https://github.com/withastro/blog-tutorial-demo). +## Enabling JSON Schema Generation + +

+ +If you are working with collections of type `data`, Astro will auto-generate JSON schema files for your editor to get IntelliSense and type-checking. A separate file will be created for each data collection in your project based on your collections defined in `src/content/config.ts` using a library called [`zod-to-json-schema`](https://github.com/StefanTerdell/zod-to-json-schema#known-issues). + +This feature requires you to manually set your schema's file path as the value for `$schema` in each data entry file of the collection: + +```json title="src/content/authors/armand.json" ins={2} +{ + "$schema": "../../../.astro/collections/authors.schema.json", + "name": "Armand", + "skills": ["Astro", "Starlight"] +} +``` + +Alternatively, you can set this value in your editor settings. For example, to set this value in [VSCode's `json.schemas` setting](https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings), provide the path of files to match and the location of your JSON schema: + +```json +{ + "json.schemas": [ + { + "fileMatch": [ + "/src/content/authors/**" + ], + "url": "./.astro/collections/authors.schema.json" + } + ] +} +``` + ## Enabling Build Caching