0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

Fix: support strict() on content collection schemas when slug is present (#10003)

* fix: use correct data object when parsing schema

* feat(test): add `strict()` to slug schema test

* chore: changeset

* docs: "Adds support for"

Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>

---------

Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
This commit is contained in:
Ben Holmes 2024-02-07 07:26:16 -05:00 committed by GitHub
parent 6eab46b84b
commit ce4283331f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Adds support for `.strict()` on content collection schemas when a custom `slug` is present.

View file

@ -126,7 +126,7 @@ export async function getEntryData(
// Use `safeParseAsync` to allow async transforms // Use `safeParseAsync` to allow async transforms
let formattedError; let formattedError;
const parsed = await (schema as z.ZodSchema).safeParseAsync(entry.unvalidatedData, { const parsed = await (schema as z.ZodSchema).safeParseAsync(data, {
errorMap(error, ctx) { errorMap(error, ctx) {
if (error.code === 'custom' && error.params?.isHoistedAstroError) { if (error.code === 'custom' && error.params?.isHoistedAstroError) {
formattedError = error.params?.astroError; formattedError = error.params?.astroError;

View file

@ -1,7 +1,8 @@
import { z, defineCollection } from 'astro:content'; import { z, defineCollection } from 'astro:content';
const withCustomSlugs = defineCollection({ const withCustomSlugs = defineCollection({
schema: z.object({}), // Ensure schema passes even when `slug` is present
schema: z.object({}).strict(),
}); });
const withSchemaConfig = defineCollection({ const withSchemaConfig = defineCollection({