-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add deleted section about json schema generation #12155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
,.mdx
and.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not only affect .json
files, it also works for .yaml
files for example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 :) |
Description (required)
Related issues & labels (optional)
file()
loader JSON schema astro#14221