Add deleted section about json schema generation#12155
Conversation
✅ Deploy Preview for astro-docs-2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
ArmandPhilippot
left a comment
There was a problem hiding this comment.
LGTM! I only left a fix (the config file) and two nits regarding paths.
|
|
||
| <p><Since v="4.13.0" /></p> | ||
|
|
||
| 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). |
There was a problem hiding this comment.
I’ve been thinking about this for quite a while. I wonder which data-type collections could benefit from this, only .json? If it’s only JSON file collections, I think it would be better to say that it only benefits them instead of implying it’s more global.
Or, if this benefits more globally, like .yaml or .toml files, since those would be data-type collections (as far as I understand, I could be wrong), then improving the meaning of that “data-type collections” concept would work here, because I find it a bit confusing.
Just my two cents.
There was a problem hiding this comment.
Nice catch, thanks! This is indeed the wording used with the previous API where data was a collection type. So we probably need to reword this part to clarify what a data collection is.
I quickly tested on my side, and the schema auto-generation works for JSON, YAML and TOML files. But now, I'm a bit confused because I tried with a collection using Markdown files and a JSON schema is also generated for those (e.g. .astro/collections/posts.schema.json). Which contradicts what we have in Experimental Intellisense for content collections:
When enabled, this feature will generate and add JSON schemas to the .astro directory in your project.
It seems the JSON schemas are always generated (for any file supported at least).
EDIT: However, it seems the .astro/collections/collections.json is only generated with the experimental flag enabled.
However, I guess there is no native support for validating a YAML or TOML file with a JSON schema (please correct me if I'm wrong) and, so, what is described here only work when using a JSON file. This can be extended to .md, .mdx and .mkdoc files using the experimental flag. Now, the grey zone to me is... is there a way to provide Intellisense to YAML and TOML file with a JSON schema?
And maybe we should rework this section to precise that the schema must be provided manually and:
- this is supported by default for JSON files,
- for
.md,.mdxand.mkdoc, the user needs to enable the experimental flag - figure out what can be done with YAML and TOML
There was a problem hiding this comment.
It does not only affect .json files, it also works for .yaml files for example
There was a problem hiding this comment.
Oh okay, I thought YAML required to install something to be able to do that doing a very quick research. So, if it's supported by default, I guess we need to verify if TOML is also supported, because it was added more recently, or if we need to precise this only applies to JSON and YAML.
There was a problem hiding this comment.
Well it depends on how your Editor handles it. But yeah for VSCode you need the redhat extension for "full yaml lsp" support. But other editors might have it built in. We shouldn't be editor specific here I think though.
I don't want this PR to look like it's ready to go when we still need to figure out how to improve that section because of API changes since its removal.
|
Will note that on Talking and Doc'ing last week, we briefly discussed where on the page this information makes sense to add because to this is does not fall under any of the existing 3 topics (Defining the collection, querying the collection generating routes from the collection) but is also not really "on the same hierarchy level" as those broad topics. This is related to the file loader, but instead something (more advanced?) that you do with a collection entry, and in fact, maybe is in some way related to the I think @delucis will be overseeing this PR, alongside and dependent upon his feature fix PR. So I wouldn't treat this as "ready to review" since it's not even correct content yet. It's just a cut and paste placeholder from the way collections worked pre-v5 right now (e.g. there is no We'll need to document how it's supposed to work with the content layer API now powering collections: does this only affect the There were a lot of things that were unclear about how this worked for new content collections when they were released in v5, which is why this section was removed at that time! It wasn't actually deleted by accident, but we didn't have confirmation for how this content needed to be updated at the time, so we could not include it. We instead went with the assumption that if this is still a thing, it will make itself an issue at some future date. THE FUTURE IS NOW! 😄 |
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
Does affect both :) |
|
@delucis I think your core PR got merged, and I remember you wanted to look into this PR too. Any updates? |
|
Update the PR with a rework of the docs! |
sarah11918
left a comment
There was a problem hiding this comment.
I think this is great, and the best placement we have for it right now.
Since this is schema related, we could consider a short line (or tip?) somewhere within /en/guides/content-collections/#defining-the-collection-schema with an inline link about using [JSON schemas for your collections](#collection-json-schemas) in your editor.
But first task, is get this all on the page! 🙌
Well the one thing here is that this is potentially a bit confusing: these schemas are NOT exactly the same thing a those schemas. They’re derived from them, but I was wondering if there could be some confusion about that, i.e. a JSON Schema is a specific file format used for validating JSON files, vs your collection schema which is a Zod schema you write. |
None of this feels particularly ergonomic 😄 Happy just to have it documented, and we'll look at a larger pass at this page (e.g. we've talked about splitting up the two loaders into individual sections) to correspond to v6! |
Description (required)
Related issues & labels (optional)
file()loader JSON schema astro#14221