UNPKG

@mintlify/validation

Version:

Validates mint.json files

42 lines (41 loc) 1.26 kB
import isAbsoluteUrl from 'is-absolute-url'; import { z } from 'zod'; import { normalizeRelativePath } from '../../../../transforms/normalizeRelativePath.js'; export const openapiStringSchema = z .string() .trim() .nonempty() .transform((value, ctx) => { if (isAbsoluteUrl(value)) { try { const url = new URL(value); if (url.protocol !== 'https:') { ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Must use protocol https', }); return z.NEVER; } } catch (_a) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid URL', }); return z.NEVER; } return value; } else { return normalizeRelativePath(value); } }); export const openapiObjSchema = z .object({ source: openapiStringSchema, directory: z.string().trim().optional(), }) .strict(); export const openApiSchema = z .union([openapiStringSchema, z.array(openapiStringSchema), openapiObjSchema]) .describe('A string or an array of strings of absolute or relative urls pointing to the OpenAPI file(s)');