Last active
April 2, 2024 18:53
-
-
Save joshdavenport/9c5d4666f653bd625c3c284bfaaca1c7 to your computer and use it in GitHub Desktop.
oEmbed format zod schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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