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:
parent
6eab46b84b
commit
ce4283331f
3 changed files with 8 additions and 2 deletions
5
.changeset/strong-pets-rhyme.md
Normal file
5
.changeset/strong-pets-rhyme.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Adds support for `.strict()` on content collection schemas when a custom `slug` is present.
|
|
@ -126,7 +126,7 @@ export async function getEntryData(
|
|||
|
||||
// Use `safeParseAsync` to allow async transforms
|
||||
let formattedError;
|
||||
const parsed = await (schema as z.ZodSchema).safeParseAsync(entry.unvalidatedData, {
|
||||
const parsed = await (schema as z.ZodSchema).safeParseAsync(data, {
|
||||
errorMap(error, ctx) {
|
||||
if (error.code === 'custom' && error.params?.isHoistedAstroError) {
|
||||
formattedError = error.params?.astroError;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { z, defineCollection } from 'astro:content';
|
||||
|
||||
const withCustomSlugs = defineCollection({
|
||||
schema: z.object({}),
|
||||
// Ensure schema passes even when `slug` is present
|
||||
schema: z.object({}).strict(),
|
||||
});
|
||||
|
||||
const withSchemaConfig = defineCollection({
|
||||
|
|
Loading…
Add table
Reference in a new issue