@mintlify/validation
Version:
Validates mint.json files
33 lines (32 loc) • 889 B
JavaScript
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);
}
});