From 5852e029a8b91aef86bdd893df6b2bde5cbc8068 Mon Sep 17 00:00:00 2001 From: Jason Green Date: Tue, 23 Nov 2021 16:52:58 -1000 Subject: [PATCH 1/5] fix(json-viewer-schema): Description not showing on oneOf and anyOf --- .../schemaRowBugs/schemaRowBugs.json | 132 ++++++++++++++++++ src/__stories__/SchemaRow.tsx | 82 +++++++++++ src/__stories__/index.ts | 1 + src/components/SchemaRow/SchemaRow.tsx | 3 +- 4 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 src/__fixtures__/schemaRowBugs/schemaRowBugs.json create mode 100644 src/__stories__/SchemaRow.tsx diff --git a/src/__fixtures__/schemaRowBugs/schemaRowBugs.json b/src/__fixtures__/schemaRowBugs/schemaRowBugs.json new file mode 100644 index 00000000..2654c029 --- /dev/null +++ b/src/__fixtures__/schemaRowBugs/schemaRowBugs.json @@ -0,0 +1,132 @@ +{ + "description": "", + "type": "object", + "properties": { + "oneOf-single-object-working-description": { + "description": "Description for oneOf with a single objects. Working as expected (WAE)", + "oneOf": [ + { + "title": "oneOf-one-item", + "properties": { + "name": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + ], + "type": "object" + }, + "oneOf-two-objects-hidden-description": { + "description": "Description for oneOf with two objects. (BUG)", + "oneOf": [ + { + "title": "oneOf-two-items-first-item", + "properties": { + "name": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + }, + { + "title": "oneOf-two-items-second-item", + "properties": { + "nameTest2": { + "type": "string" + }, + "lastNameTest2": { + "type": "string" + } + } + } + ], + "type": "object" + }, + "oneOf-one-object-hidden-description-when-empty": { + "description": "Description for oneOf. Hidden when object description is empty string. (BUG)", + "oneOf": [ + { + "title": "oneOf-two-items-first-item", + "description": "", + "properties": { + "name": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + ], + "type": "object" + }, + "anyOf-single-object-working-description": { + "description": "Description for anyOf with one object. Working as expected (WAE)", + "anyOf": [ + { + "title": "anyOf-one-item", + "properties": { + "name": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + ], + "type": "object" + }, + "anyOf-two-objects-hidden-description": { + "description": "Description of anyOf with two objects. Description hidden. (BUG)", + "anyOf": [ + { + "title": "anyOf-two-items-first-item", + "properties": { + "name": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + }, + { + "title": "anyOf-two-items-second-item", + "properties": { + "nameSecond": { + "type": "string" + }, + "lastNameSecond": { + "type": "string" + } + } + } + ], + "type": "object" + }, + "anyOf-one-object-hidden-description-when-empty": { + "description": "Description for anyOf. Hidden when object description is empty string. (BUG)", + "anyOf": [ + { + "title": "anyOf-one-item-first-item", + "description": "", + "properties": { + "name": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + ], + "type": "object" + } + } +} \ No newline at end of file diff --git a/src/__stories__/SchemaRow.tsx b/src/__stories__/SchemaRow.tsx new file mode 100644 index 00000000..0007ba3d --- /dev/null +++ b/src/__stories__/SchemaRow.tsx @@ -0,0 +1,82 @@ +import { Provider as MosaicProvider } from '@stoplight/mosaic'; +import { withKnobs } from '@storybook/addon-knobs'; +import { storiesOf } from '@storybook/react'; +import { JSONSchema4 } from 'json-schema'; +import * as React from 'react'; + +import { SchemaRow } from '../components'; +import { buildTree, findNodeWithPath } from '../components/shared/__tests__/utils'; +import { Wrapper } from './utils/Wrapper'; + +const schema: JSONSchema4 = require('../__fixtures__/schemaRowBugs/schemaRowBugs.json'); + +let tree = buildTree(schema); + +storiesOf('Bugs|SchemaRow Component.oneOf', module) + .addDecorator(withKnobs) + .addDecorator(storyFn => {storyFn()}) + .add('[WAE] - Single Object - Description Works', () => { + return ( + + + + ); + }) + .add('[BUG] - Two Objects - Description is hidden', () => { + return ( + + + + ); + }) + .add('[BUG] - Single Object - Description hidden when empty', () => { + return ( + + + + ); + }); + +storiesOf('Bugs|SchemaRow Component.anyOf', module) + .addDecorator(withKnobs) + .addDecorator(storyFn => {storyFn()}) + .add('[W.A.E] - Single Object - Description Works', () => { + return ( + + + + ); + }) + .add('[BUG] - Two Objects - Description is hidden', () => { + return ( + + + + ); + }) + .add('[BUG] - Single Object - Description hidden when empty', () => { + return ( + + + + ); + }); diff --git a/src/__stories__/index.ts b/src/__stories__/index.ts index c524f209..97e5364f 100644 --- a/src/__stories__/index.ts +++ b/src/__stories__/index.ts @@ -1,2 +1,3 @@ // NOTE: The ordering of these imports determines the ordering in Storybook import './JsonSchemaViewer'; +import './SchemaRow'; diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index 4cc74ec0..179ee9ae 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -25,7 +25,7 @@ export interface SchemaRowProps { } export const SchemaRow: React.FunctionComponent = ({ schemaNode, nestingLevel }) => { - const description = isRegularNode(schemaNode) ? schemaNode.annotations.description : null; + const description = isRegularNode(schemaNode) ? schemaNode.originalFragment.description : null; const { defaultExpandedDepth, renderRowAddon, onGoToRef, hideExamples } = useJSVOptionsContext(); @@ -119,7 +119,6 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, validations={isRegularNode(schemaNode) ? schemaNode.validations : {}} /> - {typeof description === 'string' && description.length > 0 && (
From e8ee1f9867e0fc4e0b52f94adbdde7550a093fa6 Mon Sep 17 00:00:00 2001 From: Jason Green Date: Tue, 23 Nov 2021 17:20:01 -1000 Subject: [PATCH 2/5] removed
failing test --- .../__snapshots__/index.spec.tsx.snap | 427 +++++++++++++++++- 1 file changed, 421 insertions(+), 6 deletions(-) diff --git a/src/__tests__/__snapshots__/index.spec.tsx.snap b/src/__tests__/__snapshots__/index.spec.tsx.snap index af09a013..b4dfec79 100644 --- a/src/__tests__/__snapshots__/index.spec.tsx.snap +++ b/src/__tests__/__snapshots__/index.spec.tsx.snap @@ -3291,9 +3291,6 @@ exports[`HTML Output should match references/nested.json 1`] = ` object
-
-

something

-
@@ -3310,9 +3307,6 @@ exports[`HTML Output should match references/nested.json 1`] = ` object -
-

something

-
@@ -3357,6 +3351,427 @@ exports[`HTML Output should match references/nullish.json 1`] = ` " `; +exports[`HTML Output should match schemaRowBugs/schemaRowBugs.json 1`] = ` +"
+
+
+
+
+
+
+
+
+
+
+
+
oneOf-single-object-working-description
+ oneOf-one-item +
+
+
+
+

Description for oneOf with a single objects. Working as expected (WAE)

+
+
+
+
+
+
+
+
+
+
+
+
+
+
name
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
lastName
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
oneOf-two-objects-hidden-description
+
+
+ + +
+
+ +
+
+
oneOf
+
+
+
+
+

Description for oneOf with two objects. (BUG)

+
+
+
+
+
+
+
+
+
+
+
+
+
+
name
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
lastName
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
oneOf-one-object-hidden-description-when-empty
+ oneOf-two-items-first-item +
+
+
+
+

Description for oneOf. Hidden when object description is empty string. (BUG)

+
+
+
+
+
+
+
+
+
+
+
+
+
+
name
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
lastName
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
anyOf-single-object-working-description
+ anyOf-one-item +
+
+
+
+

Description for anyOf with one object. Working as expected (WAE)

+
+
+
+
+
+
+
+
+
+
+
+
+
+
name
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
lastName
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
anyOf-two-objects-hidden-description
+
+
+ + +
+
+ +
+
+
anyOf
+
+
+
+
+

Description of anyOf with two objects. Description hidden. (BUG)

+
+
+
+
+
+
+
+
+
+
+
+
+
+
name
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
lastName
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
anyOf-one-object-hidden-description-when-empty
+ anyOf-one-item-first-item +
+
+
+
+

Description for anyOf. Hidden when object description is empty string. (BUG)

+
+
+
+
+
+
+
+
+
+
+
+
+
+
name
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
lastName
+ string +
+
+
+
+
+
+
+
+
+
+
+
+
+
+" +`; + exports[`HTML Output should match tickets.schema.json 1`] = ` "
From eb163ea5262be17d9db2e15ff01d42445da1bb20 Mon Sep 17 00:00:00 2001 From: Jason Green Date: Wed, 24 Nov 2021 08:38:19 -1000 Subject: [PATCH 3/5] changes made per @P0lip request --- src/__stories__/SchemaRow.tsx | 58 +++++++++++++------------- src/components/SchemaRow/SchemaRow.tsx | 3 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/__stories__/SchemaRow.tsx b/src/__stories__/SchemaRow.tsx index 0007ba3d..22349f77 100644 --- a/src/__stories__/SchemaRow.tsx +++ b/src/__stories__/SchemaRow.tsx @@ -1,5 +1,5 @@ import { Provider as MosaicProvider } from '@stoplight/mosaic'; -import { withKnobs } from '@storybook/addon-knobs'; +import { object, withKnobs } from '@storybook/addon-knobs'; import { storiesOf } from '@storybook/react'; import { JSONSchema4 } from 'json-schema'; import * as React from 'react'; @@ -10,39 +10,44 @@ import { Wrapper } from './utils/Wrapper'; const schema: JSONSchema4 = require('../__fixtures__/schemaRowBugs/schemaRowBugs.json'); -let tree = buildTree(schema); +const tree = buildTree(schema); + +const slugList = [ + 'oneOf-single-object-working-description', + 'oneOf-two-objects-hidden-description', + 'oneOf-one-object-hidden-description-when-empty', + 'anyOf-single-object-working-description', + 'anyOf-two-objects-hidden-description', + 'anyOf-one-object-hidden-description-when-empty', +]; storiesOf('Bugs|SchemaRow Component.oneOf', module) .addDecorator(withKnobs) .addDecorator(storyFn => {storyFn()}) .add('[WAE] - Single Object - Description Works', () => { + const node = findNodeWithPath(tree, ['properties', slugList[0]])!; + object('Schema Node', node.fragment); return ( - + ); }) .add('[BUG] - Two Objects - Description is hidden', () => { + const node = findNodeWithPath(tree, ['properties', slugList[1]])!; + object('Schema Node', node.fragment); return ( - + ); }) .add('[BUG] - Single Object - Description hidden when empty', () => { + const node = findNodeWithPath(tree, ['properties', slugList[2]])!; + object('Schema Node', node.fragment); return ( - + ); }); @@ -50,33 +55,30 @@ storiesOf('Bugs|SchemaRow Component.oneOf', module) storiesOf('Bugs|SchemaRow Component.anyOf', module) .addDecorator(withKnobs) .addDecorator(storyFn => {storyFn()}) - .add('[W.A.E] - Single Object - Description Works', () => { + .add('[WAE] - Single Object - Description Works', () => { + const node = findNodeWithPath(tree, ['properties', slugList[3]])!; + object('Schema Node', node.fragment); return ( - + ); }) .add('[BUG] - Two Objects - Description is hidden', () => { + const node = findNodeWithPath(tree, ['properties', slugList[4]])!; + object('Schema Node', node.fragment); return ( - + ); }) .add('[BUG] - Single Object - Description hidden when empty', () => { + const node = findNodeWithPath(tree, ['properties', slugList[5]])!; + object('Schema Node', node.fragment); return ( - + ); }); diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index 179ee9ae..5ad9748b 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -25,8 +25,6 @@ export interface SchemaRowProps { } export const SchemaRow: React.FunctionComponent = ({ schemaNode, nestingLevel }) => { - const description = isRegularNode(schemaNode) ? schemaNode.originalFragment.description : null; - const { defaultExpandedDepth, renderRowAddon, onGoToRef, hideExamples } = useJSVOptionsContext(); const [isExpanded, setExpanded] = React.useState( @@ -35,6 +33,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, const { selectedChoice, setSelectedChoice, choices } = useChoices(schemaNode); const typeToShow = selectedChoice.type; + const description = isRegularNode(typeToShow) ? typeToShow.annotations.description : null; const refNode = React.useMemo(() => { if (isReferenceNode(schemaNode)) { From 428fa40598b71cc9e42ee1af5bc1e766aabe183a Mon Sep 17 00:00:00 2001 From: Jason Green Date: Wed, 24 Nov 2021 10:21:39 -1000 Subject: [PATCH 4/5] removed storybook code --- .../schemaRowBugs/schemaRowBugs.json | 132 ------------------ src/__stories__/SchemaRow.tsx | 84 ----------- 2 files changed, 216 deletions(-) delete mode 100644 src/__fixtures__/schemaRowBugs/schemaRowBugs.json delete mode 100644 src/__stories__/SchemaRow.tsx diff --git a/src/__fixtures__/schemaRowBugs/schemaRowBugs.json b/src/__fixtures__/schemaRowBugs/schemaRowBugs.json deleted file mode 100644 index 2654c029..00000000 --- a/src/__fixtures__/schemaRowBugs/schemaRowBugs.json +++ /dev/null @@ -1,132 +0,0 @@ -{ - "description": "", - "type": "object", - "properties": { - "oneOf-single-object-working-description": { - "description": "Description for oneOf with a single objects. Working as expected (WAE)", - "oneOf": [ - { - "title": "oneOf-one-item", - "properties": { - "name": { - "type": "string" - }, - "lastName": { - "type": "string" - } - } - } - ], - "type": "object" - }, - "oneOf-two-objects-hidden-description": { - "description": "Description for oneOf with two objects. (BUG)", - "oneOf": [ - { - "title": "oneOf-two-items-first-item", - "properties": { - "name": { - "type": "string" - }, - "lastName": { - "type": "string" - } - } - }, - { - "title": "oneOf-two-items-second-item", - "properties": { - "nameTest2": { - "type": "string" - }, - "lastNameTest2": { - "type": "string" - } - } - } - ], - "type": "object" - }, - "oneOf-one-object-hidden-description-when-empty": { - "description": "Description for oneOf. Hidden when object description is empty string. (BUG)", - "oneOf": [ - { - "title": "oneOf-two-items-first-item", - "description": "", - "properties": { - "name": { - "type": "string" - }, - "lastName": { - "type": "string" - } - } - } - ], - "type": "object" - }, - "anyOf-single-object-working-description": { - "description": "Description for anyOf with one object. Working as expected (WAE)", - "anyOf": [ - { - "title": "anyOf-one-item", - "properties": { - "name": { - "type": "string" - }, - "lastName": { - "type": "string" - } - } - } - ], - "type": "object" - }, - "anyOf-two-objects-hidden-description": { - "description": "Description of anyOf with two objects. Description hidden. (BUG)", - "anyOf": [ - { - "title": "anyOf-two-items-first-item", - "properties": { - "name": { - "type": "string" - }, - "lastName": { - "type": "string" - } - } - }, - { - "title": "anyOf-two-items-second-item", - "properties": { - "nameSecond": { - "type": "string" - }, - "lastNameSecond": { - "type": "string" - } - } - } - ], - "type": "object" - }, - "anyOf-one-object-hidden-description-when-empty": { - "description": "Description for anyOf. Hidden when object description is empty string. (BUG)", - "anyOf": [ - { - "title": "anyOf-one-item-first-item", - "description": "", - "properties": { - "name": { - "type": "string" - }, - "lastName": { - "type": "string" - } - } - } - ], - "type": "object" - } - } -} \ No newline at end of file diff --git a/src/__stories__/SchemaRow.tsx b/src/__stories__/SchemaRow.tsx deleted file mode 100644 index 22349f77..00000000 --- a/src/__stories__/SchemaRow.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import { Provider as MosaicProvider } from '@stoplight/mosaic'; -import { object, withKnobs } from '@storybook/addon-knobs'; -import { storiesOf } from '@storybook/react'; -import { JSONSchema4 } from 'json-schema'; -import * as React from 'react'; - -import { SchemaRow } from '../components'; -import { buildTree, findNodeWithPath } from '../components/shared/__tests__/utils'; -import { Wrapper } from './utils/Wrapper'; - -const schema: JSONSchema4 = require('../__fixtures__/schemaRowBugs/schemaRowBugs.json'); - -const tree = buildTree(schema); - -const slugList = [ - 'oneOf-single-object-working-description', - 'oneOf-two-objects-hidden-description', - 'oneOf-one-object-hidden-description-when-empty', - 'anyOf-single-object-working-description', - 'anyOf-two-objects-hidden-description', - 'anyOf-one-object-hidden-description-when-empty', -]; - -storiesOf('Bugs|SchemaRow Component.oneOf', module) - .addDecorator(withKnobs) - .addDecorator(storyFn => {storyFn()}) - .add('[WAE] - Single Object - Description Works', () => { - const node = findNodeWithPath(tree, ['properties', slugList[0]])!; - object('Schema Node', node.fragment); - return ( - - - - ); - }) - .add('[BUG] - Two Objects - Description is hidden', () => { - const node = findNodeWithPath(tree, ['properties', slugList[1]])!; - object('Schema Node', node.fragment); - return ( - - - - ); - }) - .add('[BUG] - Single Object - Description hidden when empty', () => { - const node = findNodeWithPath(tree, ['properties', slugList[2]])!; - object('Schema Node', node.fragment); - return ( - - - - ); - }); - -storiesOf('Bugs|SchemaRow Component.anyOf', module) - .addDecorator(withKnobs) - .addDecorator(storyFn => {storyFn()}) - .add('[WAE] - Single Object - Description Works', () => { - const node = findNodeWithPath(tree, ['properties', slugList[3]])!; - object('Schema Node', node.fragment); - return ( - - - - ); - }) - .add('[BUG] - Two Objects - Description is hidden', () => { - const node = findNodeWithPath(tree, ['properties', slugList[4]])!; - object('Schema Node', node.fragment); - return ( - - - - ); - }) - .add('[BUG] - Single Object - Description hidden when empty', () => { - const node = findNodeWithPath(tree, ['properties', slugList[5]])!; - object('Schema Node', node.fragment); - return ( - - - - ); - }); From 2535e4240b9768d75bf5ecf1de965af3bb6035d8 Mon Sep 17 00:00:00 2001 From: Jason Green Date: Wed, 24 Nov 2021 10:38:40 -1000 Subject: [PATCH 5/5] removed
to pass test --- .../__snapshots__/index.spec.tsx.snap | 427 +----------------- 1 file changed, 6 insertions(+), 421 deletions(-) diff --git a/src/__tests__/__snapshots__/index.spec.tsx.snap b/src/__tests__/__snapshots__/index.spec.tsx.snap index b4dfec79..af09a013 100644 --- a/src/__tests__/__snapshots__/index.spec.tsx.snap +++ b/src/__tests__/__snapshots__/index.spec.tsx.snap @@ -3291,6 +3291,9 @@ exports[`HTML Output should match references/nested.json 1`] = ` object
+
+

something

+
@@ -3307,6 +3310,9 @@ exports[`HTML Output should match references/nested.json 1`] = ` object +
+

something

+
@@ -3351,427 +3357,6 @@ exports[`HTML Output should match references/nullish.json 1`] = ` " `; -exports[`HTML Output should match schemaRowBugs/schemaRowBugs.json 1`] = ` -"
-
-
-
-
-
-
-
-
-
-
-
-
oneOf-single-object-working-description
- oneOf-one-item -
-
-
-
-

Description for oneOf with a single objects. Working as expected (WAE)

-
-
-
-
-
-
-
-
-
-
-
-
-
-
name
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
lastName
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
oneOf-two-objects-hidden-description
-
-
- - -
-
- -
-
-
oneOf
-
-
-
-
-

Description for oneOf with two objects. (BUG)

-
-
-
-
-
-
-
-
-
-
-
-
-
-
name
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
lastName
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
oneOf-one-object-hidden-description-when-empty
- oneOf-two-items-first-item -
-
-
-
-

Description for oneOf. Hidden when object description is empty string. (BUG)

-
-
-
-
-
-
-
-
-
-
-
-
-
-
name
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
lastName
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
anyOf-single-object-working-description
- anyOf-one-item -
-
-
-
-

Description for anyOf with one object. Working as expected (WAE)

-
-
-
-
-
-
-
-
-
-
-
-
-
-
name
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
lastName
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
anyOf-two-objects-hidden-description
-
-
- - -
-
- -
-
-
anyOf
-
-
-
-
-

Description of anyOf with two objects. Description hidden. (BUG)

-
-
-
-
-
-
-
-
-
-
-
-
-
-
name
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
lastName
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
anyOf-one-object-hidden-description-when-empty
- anyOf-one-item-first-item -
-
-
-
-

Description for anyOf. Hidden when object description is empty string. (BUG)

-
-
-
-
-
-
-
-
-
-
-
-
-
-
name
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
lastName
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-" -`; - exports[`HTML Output should match tickets.schema.json 1`] = ` "