@mintlify/validation
Version:
Validates mint.json files
42 lines (41 loc) • 1.4 kB
JavaScript
import { z } from 'zod';
import { isAbsoluteUrl } from '../../../../isAbsoluteUrl.js';
import { normalizeRelativePath } from '../../../../transforms/normalizeRelativePath.js';
export const asyncapiStringSchema = z
.string()
.trim()
.nonempty()
.transform((value, ctx) => {
if (isAbsoluteUrl(value)) {
try {
const url = new URL(value);
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Must use protocol https or http. Urls with 'http://' are only supported with cli option --local-schema",
});
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 asyncapiObjSchema = z
.object({
source: asyncapiStringSchema,
directory: z.string().trim().optional(),
})
.strict();
export const asyncApiSchema = z
.union([asyncapiStringSchema, z.array(asyncapiStringSchema), asyncapiObjSchema])
.describe('A string or an array of strings of absolute or relative urls pointing to the AsyncAPI file(s)');