-
Notifications
You must be signed in to change notification settings - Fork 45
fix(json-schema-viewer): Description for oneOf/anyOf does not display #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(json-schema-viewer): Description for oneOf/anyOf does not display #176
Conversation
src/__stories__/SchemaRow.tsx
Outdated
|
|
||
| let tree = buildTree(schema); | ||
|
|
||
| storiesOf('Bugs|SchemaRow Component.oneOf', module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether we need all of these stories.
Overall, a storybook should be used to demonstrate the functionalities of a component, and not serve us a way to let us reproduce a bug - bugs should be covered by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip : I created these bugs in Storybook two-fold:
- So that others had a way of seeing the bugs in action
- So that I could debug them.
It was expected that these would be taken out of Storybook after the bug fix. Instead of yalc'ing, is there another method of debugging you can recommend (other than using Storybook)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that others had a way of seeing the bugs in action
It was expected that these would be taken out of Storybook after the bug fix. I
gotcha, sounds good 👍
Instead of yalc'ing, is there another method of debugging you can recommend (other than using Storybook)?
You could write a test for that, we have quite a few of them, and then run debugger from there or perform a console based debugging.
|
|
||
| export const SchemaRow: React.FunctionComponent<SchemaRowProps> = ({ schemaNode, nestingLevel }) => { | ||
| const description = isRegularNode(schemaNode) ? schemaNode.annotations.description : null; | ||
| const description = isRegularNode(schemaNode) ? schemaNode.originalFragment.description : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one should never operate on originalFragment. I believe we should make it private to indicate that.
originalFragment may come in handy in certain situations, but it's certainly not meant to be used this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putting the above comment aside, this code won't work the way user expects.
Consider the following:
{
"type": "object",
"properties": {
"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"
}
}
},
{
"description": "Woooo for oneOf with two objects. (BUG)",
"title": "oneOf-two-items-second-item",
"properties": {
"nameTest2": {
"type": "string"
},
"lastNameTest2": {
"type": "string"
}
}
}
],
"type": "object"
}
}
}in your case, we'll always display the description placed under oneOf, which is incorrect.
json-schema-tree ensures the above description placed under oneOf (and any other compound keyword like anyOf) is inserted into each dependency of it, so you can rely on it.
const { defaultExpandedDepth, renderRowAddon, onGoToRef, hideExamples } = useJSVOptionsContext();
const [isExpanded, setExpanded] = React.useState<boolean>(
!isMirroredNode(schemaNode) && nestingLevel <= defaultExpandedDepth,
);
const { selectedChoice, setSelectedChoice, choices } = useChoices(schemaNode);
const typeToShow = selectedChoice.type;
const description = isRegularNode(selectedChoice.type) ? selectedChoice.type.annotations.description : null;this will do the trick.
If the description is empty, I'd say a user wants to hide it for some reason, and we shouldn't display anything.
|
let's remove these stories too and have a test instead. |
|
@P0lip : For |
Yeah, I agree. That feels wrong. We should change that behavior in JSE in Studio. |
|
I'm going to do it ^ |
P0lip
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 just make sure to clean up those stories and we should be good to go.
|
@P0lip : I'm going to remove the Storybook code :) |
| @@ -1,2 +1,3 @@ | |||
| // NOTE: The ordering of these imports determines the ordering in Storybook | |||
| import './JsonSchemaViewer'; | |||
| import './SchemaRow'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import './SchemaRow'; |
we probably no longer need it do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jgreen44 was trying to review this but storybook will not start for me. Can you please make a follow up PR and remove this? TY!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulatulis : I'm sorry, I'm not sure I understand what you mean by "make a follow up PR and remove this"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you import SchemaRow into this file, but I believe it needs to be removed per @P0lip 's suggested change above. When you check out the main branch and try running yarn storybook, are you able to get it started? Maybe it's just me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storybook has been removed. I will make another PR to remove ./SchemaRow import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I believe she is referring to the line removal suggestion Jakub made)
|
🎉 This PR is included in version 4.3.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |







Addresses #7465
Summary:
When selecting
oneOforanyOfand providing a description, the description fails to show. There are several cases where the description will not show:I have provided a video to explain these bugs:
7465.-.2021.11.23.at.4.33.37.PM.-.Bug.Showcase.mov
To Test:
yarn storybook7465.-.2021.11.23.at.4.45.32.PM.-.Storybook.Explanation.mp4
Changing one line of code fixed this issue, but I'm unclear as to why
schemaNode.annotations.descriptionswas used instead ofschemaNode.originalFragment.descriptionsChecklist