Skip to content

Commit

Permalink
fix(rss): rssSchema definition to allow calling standard zod object m…
Browse files Browse the repository at this point in the history
…ethods (#9746)

* fix(rss): rssSchema definition to allow calling standard zod object methods

* fix: condition
  • Loading branch information
florian-lefebvre committed Jan 22, 2024
1 parent d0742bc commit 7356336
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-icons-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/rss": patch
---

Fixes `rssSchema` definition to allow calling standard zod object methods (like `extend`)
24 changes: 7 additions & 17 deletions packages/astro-rss/src/schema.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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"]
})

0 comments on commit 7356336

Please sign in to comment.