Skip to content

Commit

Permalink
feat: add constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Fedoseev committed Mar 26, 2024
1 parent a6aef4e commit 7b78ff2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
53 changes: 48 additions & 5 deletions src/includer/traverse/tables.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import RefsService from '../services/refs';
import stringify from 'json-stringify-safe';

import {anchor, bold, table, tableParameterName} from '../ui';
import {anchor, block, bold, table, tableParameterName} from '../ui';
import {concatNewLine} from '../utils';
import {BLOCK, EOL} from '../constants';
import {EOL} from '../constants';
import {OpenJSONSchema, OpenJSONSchemaDefinition} from '../models';
import {collectRefs, extractOneOfElements, inferType, typeToText} from './types';

Expand Down Expand Up @@ -61,7 +61,7 @@ function prepareObjectSchemaTable(schema: OpenJSONSchema): PrepareObjectSchemaTa
const name = tableParameterName(key, isRequired(key, merged));
const {type, description, ref, runtimeRef} = prepareTableRowData(value, key, tableRef);

result.rows.push([name, `${bold('Type: ' + type)}${BLOCK}${BLOCK}${description}`]);
result.rows.push([name, block([`${bold('Type:')} ${type}`, description])]);

if (ref) {
result.refs.push(...ref);
Expand Down Expand Up @@ -145,7 +145,7 @@ export function prepareTableRowData(
return {
type: `${anchor(inner.runtimeRef, key)}[]`,
runtimeRef: inner.runtimeRef,
description: innerDescription,
description: prepareComplexDescription(innerDescription, value),
};
}

Expand All @@ -156,7 +156,7 @@ export function prepareTableRowData(
type: returnType,
// if inner.ref present, inner description will be in separate table
ref: inner.ref,
description: innerDescription,
description: prepareComplexDescription(innerDescription, value),
};
}

Expand Down Expand Up @@ -219,6 +219,49 @@ function prepareComplexDescription(baseDescription: string, value: OpenJSONSchem
);
}

if (typeof value.maxItems !== 'undefined') {
description = concatNewLine(
description,
`<span style="color:gray;">Max items</span>: \`${value.maxItems}\``,
);
}

if (typeof value.minItems !== 'undefined') {
description = concatNewLine(
description,
`<span style="color:gray;">Min items</span>: \`${value.minItems}\``,
);
}

if (typeof value.pattern !== 'undefined') {
description = concatNewLine(
description,
`<span style="color:gray;">Pattern</span>: \`${value.pattern}\``,
);
}

if (typeof value.uniqueItems !== 'undefined') {
description = concatNewLine(description, `<span style="color:gray;">Unique items</span>`);
}

if (typeof value.minimum !== 'undefined') {
description = concatNewLine(
description,
`<span style="color:gray;">Min value${
value.exclusiveMinimum ? ' (exclusive)' : ''
}</span>: \`${value.minimum}\``,
);
}

if (typeof value.maximum !== 'undefined') {
description = concatNewLine(
description,
`<span style="color:gray;">Max value${
value.exclusiveMaximum ? ' (exclusive)' : ''
}</span>: \`${value.maximum}\``,
);
}

return description;
}

Expand Down
6 changes: 4 additions & 2 deletions src/includer/ui/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import stringify from 'json-stringify-safe';
import RefsService from '../services/refs';

import {
BLOCK,
COOKIES_SECTION_NAME,
HEADERS_SECTION_NAME,
INFO_TAB_NAME,
Expand Down Expand Up @@ -204,7 +203,10 @@ function parameterRow(param: Parameter): {cells: string[]; ref?: TableRef[]} {
description = concatNewLine(description, `Default: \`${param.default}\``);
}
return {
cells: [tableParameterName(param.name, param.required), `${bold('Type: ' + row.type)}${BLOCK}${BLOCK}${description}`],
cells: [
tableParameterName(param.name, param.required),
block([`${bold('Type:')} ${row.type}`, description]),
],
ref: row.ref,
};
}
Expand Down

0 comments on commit 7b78ff2

Please sign in to comment.