Skip to content

Instantly share code, notes, and snippets.

@joshdavenport
Last active April 2, 2024 18:53
Show Gist options
  • Save joshdavenport/9c5d4666f653bd625c3c284bfaaca1c7 to your computer and use it in GitHub Desktop.
Save joshdavenport/9c5d4666f653bd625c3c284bfaaca1c7 to your computer and use it in GitHub Desktop.
oEmbed format zod schema
const oembedSchema = z.discriminatedUnion('type', [
z.object({
type: z.literal('photo'),
url: z.string(),
width: z.number(),
height: z.number(),
}),
z.object({
type: z.literal('video'),
html: z.string(),
width: z.number(),
height: z.number(),
}),
z.object({
type: z.literal('link'),
}),
z.object({
type: z.literal('rich'),
html: z.string(),
width: z.number(),
height: z.number(),
}),
])
.and(
z.object({
version: z.string(),
title: z.string().optional(),
author_name: z.string().optional(),
author_url: z.string().optional(),
provider_name: z.string().optional(),
provider_url: z.string().optional(),
cache_age: z.number().optional(),
thumbnail_url: z.string().optional(),
thumbnail_width: z.number().optional(),
thumbnail_height: z.number().optional(),
}),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment