diff --git a/src/utils/openapi.ts b/src/utils/openapi.ts index 2836cfed..c2f1b0b4 100644 --- a/src/utils/openapi.ts +++ b/src/utils/openapi.ts @@ -368,6 +368,14 @@ export function isNamedDefinition(pointer?: string): boolean { return /^#\/components\/schemas\/[^\/]+$/.test(pointer || ''); } +function humanizeMultipleOfConstraint(multipleOf: number | undefined): string | undefined { + if (multipleOf === undefined) return; + const strigifiedMultipleOf = multipleOf.toString(10); + const parts = strigifiedMultipleOf.split('.'); + if (parts.length < 2 || !/^0*1$/.test(parts[1])) return `multiple of ${strigifiedMultipleOf}`; + return `decimals <= ${parts[1].length} digits`; +} + function humanizeRangeConstraint( description: string, min: number | undefined, @@ -406,6 +414,11 @@ export function humanizeConstraints(schema: OpenAPISchema): string[] { res.push(arrayRange); } + const multipleOfConstraint = humanizeMultipleOfConstraint(schema.multipleOf); + if (multipleOfConstraint !== undefined) { + res.push(multipleOfConstraint); + } + let numberRange; if (schema.minimum !== undefined && schema.maximum !== undefined) { numberRange = schema.exclusiveMinimum ? '( ' : '[ ';