feat(openapi): recognise the modern Zod integer formats (#1649)

This commit is contained in:
Hampus
2026-08-15 21:01:43 +02:00
committed by GitHub
parent e0876d719c
commit 0be2a7fed9
2 changed files with 10 additions and 0 deletions
@@ -74,6 +74,8 @@ interface ZodInternalDefinition {
getter?: () => ZodTypeAny;
pattern?: RegExp;
transform?: (input: unknown) => unknown;
check?: string;
format?: string;
}
interface ZodInternalSchema {
@@ -258,6 +258,7 @@ export function extractStringConstraints(schema: ZodTypeAny): {
if (stringProperties._regex != null) result.pattern = stringProperties._regex.source;
return result;
}
const INTEGER_NUMBER_FORMATS = new Set(['safeint', 'int32', 'uint32']);
export function extractNumberConstraints(schema: ZodTypeAny): {
minimum?: number;
maximum?: number;
@@ -277,6 +278,13 @@ export function extractNumberConstraints(schema: ZodTypeAny): {
if (check.isInt === true) result.isInt = true;
if (check.format != null) result.format = check.format;
}
const definition = getZodDefinition(schema);
if (definition.check === 'number_format' && definition.format != null) {
result.format = definition.format;
if (INTEGER_NUMBER_FORMATS.has(definition.format)) {
result.isInt = true;
}
}
return result;
}
export function getDefaultValue(schema: ZodTypeAny): unknown {