Skip to content

Commit

Permalink
fix: liner
Browse files Browse the repository at this point in the history
  • Loading branch information
v8tenko committed Apr 22, 2024
1 parent 54ee693 commit 5d68398
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
59 changes: 28 additions & 31 deletions src/includer/traverse/description.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
import { EOL } from "../constants";
import { OpenJSONSchema } from "../models";
import { concatNewLine } from "../utils";
import {EOL} from '../constants';
import {OpenJSONSchema} from '../models';
import {concatNewLine} from '../utils';

type Field = {
key: keyof OpenJSONSchema;
label: string;
computed?: unknown;
notWrapValueIntoCode?: boolean;
}
};

type Fields = (Field | ((value: OpenJSONSchema) => Field | undefined))[]
type Fields = (Field | ((value: OpenJSONSchema) => Field | undefined))[];

/* @todo add i18n */
const fields: Fields = [
{
key: 'default',
label: 'Default'
label: 'Default',
},
{
key: 'example',
label: 'Example'
label: 'Example',
},
{
key: 'minLength',
label: 'Min length'
label: 'Min length',
},
{
key: 'maxLength',
label: 'Max length'
label: 'Max length',
},
{
key: 'maxItems',
label: 'Max items'
label: 'Max items',
},
{
key: 'minItems',
label: 'Min items'
label: 'Min items',
},
{
key: 'pattern',
label: 'Pattern'
label: 'Pattern',
},
{
key: 'uniqueItems',
label: 'Unique items'
label: 'Unique items',
},
(value) => {
return {
key: 'minimum',
label: `Min value${value.exclusiveMinimum ? ' (exclusive)' : ''}`
}
label: `Min value${value.exclusiveMinimum ? ' (exclusive)' : ''}`,
};
},
(value) => {
return {
key: 'maximum',
label: `Max value${value.exclusiveMaximum ? ' (exclusive)' : ''}`
}
label: `Max value${value.exclusiveMaximum ? ' (exclusive)' : ''}`,
};
},
(value: OpenJSONSchema) => {
const enumValues = value.enum?.map((s) => `\`${s}\``).join(', ');

if (!enumValues) {
return undefined
return undefined;
}

return {
computed: enumValues as Field['key'],
notWrapValueIntoCode: true,
key: 'enum',
label: 'Enum'
}
}
]
label: 'Enum',
};
},
];

function prepareComplexDescription(baseDescription: string, value: OpenJSONSchema): string {
const description = baseDescription + EOL;
return fields.reduce((acc, curr) => {

return fields.reduce((acc, curr) => {
const field = typeof curr === 'function' ? curr(value) : curr;

if (typeof field === 'undefined' || !value[field.key]) {
Expand All @@ -85,9 +85,8 @@ function prepareComplexDescription(baseDescription: string, value: OpenJSONSchem

const {key, label, computed, notWrapValueIntoCode} = field;

return concatConstraint(acc, computed || value[key], label + ':', notWrapValueIntoCode)

}, description)
return concatConstraint(acc, computed || value[key], label + ':', notWrapValueIntoCode);
}, description);
}

function concatConstraint(
Expand Down Expand Up @@ -116,7 +115,5 @@ function prepareConstraintValue(value: unknown, notWrapValueIntoCode: boolean) {
return notWrapValueIntoCode ? value : `\`${value}\``;
}



export {fields, prepareComplexDescription}
export default {fields, prepareComplexDescription}
export {fields, prepareComplexDescription};
export default {fields, prepareComplexDescription};
2 changes: 1 addition & 1 deletion src/includer/traverse/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {anchor, block, bold, table, tableParameterName} from '../ui';
import {concatNewLine} from '../utils';
import {OpenJSONSchema, OpenJSONSchemaDefinition} from '../models';
import {collectRefs, extractOneOfElements, inferType, typeToText} from './types';
import { prepareComplexDescription } from './description';
import {prepareComplexDescription} from './description';

type TableRow = [string, string];

Expand Down

0 comments on commit 5d68398

Please sign in to comment.