mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
feat(openapi): recognise the modern Zod integer formats (#1649)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user