mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-09 06:34:53 +03:00
feat: visualise 'multipleOf' property
This commit is contained in:
parent
4494f80dbc
commit
689fe64b2d
|
@ -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 ? '( ' : '[ ';
|
||||
|
|
Loading…
Reference in New Issue
Block a user