mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 13:44:54 +03:00
simplify humanizeNumberRange function
This commit is contained in:
parent
8af06952a4
commit
2ac7ffa7f6
|
@ -420,8 +420,6 @@ function humanizeRangeConstraint(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function humanizeNumberRange(schema: OpenAPISchema): string | undefined {
|
export function humanizeNumberRange(schema: OpenAPISchema): string | undefined {
|
||||||
let result;
|
|
||||||
|
|
||||||
const minimum =
|
const minimum =
|
||||||
typeof schema.exclusiveMinimum === 'number'
|
typeof schema.exclusiveMinimum === 'number'
|
||||||
? Math.min(schema.exclusiveMinimum, schema.minimum ?? Infinity)
|
? Math.min(schema.exclusiveMinimum, schema.minimum ?? Infinity)
|
||||||
|
@ -436,20 +434,14 @@ export function humanizeNumberRange(schema: OpenAPISchema): string | undefined {
|
||||||
typeof schema.exclusiveMaximum === 'number' ? true : schema.exclusiveMaximum;
|
typeof schema.exclusiveMaximum === 'number' ? true : schema.exclusiveMaximum;
|
||||||
|
|
||||||
if (minimum !== undefined && maximum !== undefined) {
|
if (minimum !== undefined && maximum !== undefined) {
|
||||||
result = exclusiveMinimum ? '( ' : '[ ';
|
return `${exclusiveMinimum ? '( ' : '[ '}${minimum} .. ${maximum}${
|
||||||
result += minimum;
|
exclusiveMaximum ? ' )' : ' ]'
|
||||||
result += ' .. ';
|
}`;
|
||||||
result += maximum;
|
|
||||||
result += exclusiveMaximum ? ' )' : ' ]';
|
|
||||||
} else if (maximum !== undefined) {
|
} else if (maximum !== undefined) {
|
||||||
result = exclusiveMaximum ? '< ' : '<= ';
|
return `${exclusiveMaximum ? '< ' : '<= '}${maximum}`;
|
||||||
result += maximum;
|
|
||||||
} else if (minimum !== undefined) {
|
} else if (minimum !== undefined) {
|
||||||
result = exclusiveMinimum ? '> ' : '>= ';
|
return `${exclusiveMinimum ? '> ' : '>= '}${minimum}`;
|
||||||
result += minimum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function humanizeConstraints(schema: OpenAPISchema): string[] {
|
export function humanizeConstraints(schema: OpenAPISchema): string[] {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user