simplify humanizeNumberRange function

This commit is contained in:
Oprysk 2021-11-24 12:32:16 +02:00
parent 8af06952a4
commit 2ac7ffa7f6

View File

@ -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[] {