Skip to content

Commit 91457f5

Browse files
committed
feat: custom dividers texts
1 parent 3b7b3d1 commit 91457f5

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

src/components/SchemaRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export const SchemaRow: React.FunctionComponent<ISchemaRow> = ({
5252
css={{ userSelect: 'text' }}
5353
{...props}
5454
>
55-
{node.showDivider && (
55+
{node.divider && (
5656
<Divider ml="-24px" width={`calc(100% + 24px)`}>
57-
or
57+
{node.divider}
5858
</Divider>
5959
)}
6060

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface ITreeNodeMeta {
5555
name?: string;
5656
additional?: IArrayNode['additionalItems'] | IObjectNode['additionalProperties'];
5757
path: JsonPath;
58-
showDivider?: boolean;
58+
divider?: string;
5959
subtype?: IBaseNode['type'];
6060
expanded?: boolean;
6161
required?: boolean;

src/utils/__tests__/__snapshots__/renderSchema.spec.ts.snap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ Array [
7474
"type": "string",
7575
},
7676
},
77-
"showDivider": false,
7877
"type": "object",
7978
"validations": Object {},
8079
},
@@ -107,6 +106,7 @@ Array [
107106
"metadata": Object {
108107
"additionalProperties": undefined,
109108
"annotations": Object {},
109+
"divider": "and",
110110
"enum": undefined,
111111
"id": "random-id",
112112
"path": Array [
@@ -136,7 +136,6 @@ Array [
136136
"type": "string",
137137
},
138138
},
139-
"showDivider": false,
140139
"type": "object",
141140
"validations": Object {},
142141
},
@@ -509,7 +508,6 @@ Array [
509508
"type": "string",
510509
},
511510
},
512-
"showDivider": false,
513511
"type": "object",
514512
"validations": Object {},
515513
},
@@ -565,6 +563,7 @@ Array [
565563
"metadata": Object {
566564
"additionalItems": undefined,
567565
"annotations": Object {},
566+
"divider": "and/or",
568567
"enum": undefined,
569568
"id": "random-id",
570569
"items": undefined,
@@ -574,7 +573,6 @@ Array [
574573
"properties",
575574
1,
576575
],
577-
"showDivider": true,
578576
"subtype": "integer",
579577
"type": "array",
580578
"validations": Object {},

src/utils/dividers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Dictionary } from '@stoplight/types';
2+
import { JSONSchema4CombinerName } from '../types';
3+
4+
export const DIVIDERS: Dictionary<string, JSONSchema4CombinerName> = {
5+
allOf: 'and',
6+
anyOf: 'and/or',
7+
oneOf: 'or',
8+
};

src/utils/renderSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { JSONSchema4 } from 'json-schema';
22
import _isEmpty = require('lodash/isEmpty');
33
import { IArrayNode, IObjectNode, ITreeNodeMeta, SchemaKind, SchemaTreeListNode } from '../types';
4+
import { DIVIDERS } from './dividers';
45
import { isCombiner } from './isCombiner';
56
import { isRef } from './isRef';
67
import { lookupRef } from './lookupRef';
@@ -78,14 +79,13 @@ export const renderSchema: Walker = function*(schema, dereferencedSchema, level
7879
};
7980

8081
if (node.properties !== undefined) {
81-
const isConditionalCombiner = node.combiner === 'anyOf' || node.combiner === 'oneOf';
8282
for (const [i, property] of node.properties.entries()) {
8383
if ('type' in node) {
8484
property.type = node.type;
8585
}
8686

8787
yield* renderSchema(property, dereferencedSchema, level + 1, {
88-
showDivider: isConditionalCombiner && i !== 0,
88+
...(i !== 0 && { divider: DIVIDERS[node.combiner] }),
8989
path: [...path, 'properties', i],
9090
});
9191
}

0 commit comments

Comments
 (0)