-
Notifications
You must be signed in to change notification settings - Fork 212
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
feat(api): make API component resolve inline and remote refs #575
Conversation
Taken over by @mmiask |
using bundled data instead of dereferenced in API container
@@ -0,0 +1,47 @@ | |||
import $RefParser from '@stoplight/json-schema-ref-parser'; | |||
import { NodeType } from '@stoplight/types'; | |||
import { isObject } from 'lodash'; |
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 { isObject } from 'lodash'; | |
import { isObjectLike } from 'lodash'; |
isObject
returns true for functions.
(or isPlainObject
)
We can leave it as well too, as I doubt function will ever be provided.
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 this on hold until the discussion is settled in #570. |
@mallachari I modified some files related to |
Deploy preview for stoplight-elements ready! Built with commit 5792351 |
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.
There is a lot of passing around of the base URL and the document, and we're bundling all over the place.
Is there anything preventing us to do the bundling once at the container level then be done with it?
Done correctly, that would even reduce your diff size, currently there's quite some boilerplate and duplicated logic.
</Tabs> | ||
) : ( | ||
<Docs className="mx-auto p-4" nodeType={nodeType} nodeData={data} headless /> | ||
<InlineRefResolverProvider document={document}> |
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.
As this is a context we shouldn't need to pass document
all the way down with props. Did you try to put InlineRefResolverProvider
at the StackedLayout
root level?
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.
Almost there. Much less redundant data passing down, much more centralized resolving, good job.
There is still some redundant data being passed down. nodeType, bundledNodeData, uriMap, they all refer to mostly the same information.
The simplest way to think about the problem would be to bundle all the $refs into the document on the container level before we start processing it, then the processing logic doesn't need to change at all.
linkComponent?: React.ComponentType<ILinkComponentProps>; | ||
apiDescriptionUrl?: string; |
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.
With the cleaned up implementation this was made redundant here, we're not using it anywhere. Let's remove it.
@@ -26,7 +27,7 @@ const itemMatchesHash = (hash: string, item: Pick<ItemRowProps, 'title' | 'type' | |||
return hash.substr(1) === `${item.title}-${item.type}`; | |||
}; | |||
|
|||
export const StackedLayout: React.FC<StackedLayoutProps> = ({ uriMap, tree }) => { | |||
export const StackedLayout: React.FC<StackedLayoutProps> = ({ uriMap, tree, bundledNodeData }) => { |
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.
Cheating 😛
WebStorm immediately gave me an unused variable warning. And it is right, trying your external ref file: https://raw.githubusercontent.com/mmiask/anothertesting/master/reference/test.v1.yaml with the stacked layout crashes immediately upon opening the Endpoints group.
I pushed some changes that implement the centralized bundling I was imagining. Let me know what you think @mmiask @mallachari Even with some bugfixes added in the bundling hook it still reduced the diff from +109-31 & 7 files to +93-26 & 5 files as the presentational components are now ignorant of the bundling logic. |
@marcelltoth I was just about to push my changes that used |
It's more compact now, I like it this way. |
Resolves #570
Inline ref resolution is in place, remote resolution is TBD.