-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat: experimental content collection JSON schemas #10145
feat: experimental content collection JSON schemas #10145
Conversation
🦋 Changeset detectedLatest commit: 413bafd The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @alexanderniebuhr and the rest of your teammates on |
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.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
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.
Looks great! Have a few suggestions still, but not blocking so I'm preemptively approving.
let zodSchemaForJson = collectionConfig.schema; | ||
if (zodSchemaForJson instanceof z.ZodObject) { | ||
zodSchemaForJson = zodSchemaForJson.extend({ | ||
$schema: z.string().optional(), | ||
}); | ||
} |
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, this seems like a reasonable way to handle it!
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.
Thanks for this @alexanderniebuhr ! Left some things to think about for the changeset, which will then take us on to the actual docs content!
Because this is experimental, we typically would not mention it in docs on e.g. the content collections page. So, we don't need another docs PR, because this should be the only place it appears while experimental! 🙌
packages/astro/src/@types/astro.ts
Outdated
* @default `false` | ||
* @version 4.5.0 | ||
* @description | ||
* Enables generation of JSON Schema files for content collections of type `data`. |
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.
"Once the changeset is figured out, those instructions, limitations etc should also be here! This is the place in docs where people will go to figure out what this does and how it works!
When we like the changeset, it can be a mostly copy-paste here, except that this can be less "here's a new feature!" and more just boring, "here's what you do."
Reminder to self: this should also link to the content collections page in docs.
} catch (err) { | ||
logger.warn( | ||
'content', | ||
`An error was encountered while creating the Json schema. Proceeding without it. Error: ${err}` |
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.
Not sure if this warning also needs rewording. If so please feel free to commit that yourself.
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.
JSON is probably all caps when referred to as a name/noun?
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.
According to https://json-schema.org/ yes, so I've updated the warning message
Co-authored-by: Sarah Rainsberger <[email protected]>
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 think just some tiny nits to clean up here, otherwise, LGTM!
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Changes
import { defineConfig } from 'astro/config'; export default defineConfig({ experimental: { + contentCollectionJsonSchema: true } });
$schema
property in their zod schema, otherwise they get a warningimport { defineCollection, z } from 'astro:content'; const test = defineCollection({ type: 'data', schema: z.object({ + "$schema": z.string().optional(), test: z.string() }), }); export const collections = { test };
{ + "$schema": "../../../.astro/schemas/collections/i18n.json", "homepage": { "greeting": "ME", "preamble": "ME" } }
Testing
Docs