From 7356336d18c916804001bdf64bff5445d82baceb Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Mon, 22 Jan 2024 13:07:29 +0100 Subject: [PATCH] fix(rss): rssSchema definition to allow calling standard zod object methods (#9746) * fix(rss): rssSchema definition to allow calling standard zod object methods * fix: condition --- .changeset/mighty-icons-try.md | 5 +++++ packages/astro-rss/src/schema.ts | 24 +++++++----------------- 2 files changed, 12 insertions(+), 17 deletions(-) create mode 100644 .changeset/mighty-icons-try.md diff --git a/.changeset/mighty-icons-try.md b/.changeset/mighty-icons-try.md new file mode 100644 index 000000000000..86965b765315 --- /dev/null +++ b/.changeset/mighty-icons-try.md @@ -0,0 +1,5 @@ +--- +"@astrojs/rss": patch +--- + +Fixes `rssSchema` definition to allow calling standard zod object methods (like `extend`) diff --git a/packages/astro-rss/src/schema.ts b/packages/astro-rss/src/schema.ts index 788fe86fb3be..773d39cf2020 100644 --- a/packages/astro-rss/src/schema.ts +++ b/packages/astro-rss/src/schema.ts @@ -1,6 +1,8 @@ import { z } from 'astro/zod'; -const sharedSchema = z.object({ +export const rssSchema = z.object({ + title: z.string().optional(), + description: z.string().optional(), pubDate: z .union([z.string(), z.number(), z.date()]) .optional() @@ -20,19 +22,7 @@ const sharedSchema = z.object({ .optional(), link: z.string().optional(), content: z.string().optional(), -}); - -export const rssSchema = z.union([ - z - .object({ - title: z.string(), - description: z.string().optional(), - }) - .merge(sharedSchema), - z - .object({ - title: z.string().optional(), - description: z.string(), - }) - .merge(sharedSchema), -]); +}).refine(val => val.title || val.description, { + message: "At least title or description must be provided.", + path: ["title", "description"] +}) \ No newline at end of file