-
Notifications
You must be signed in to change notification settings - Fork 211
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
Changes from 11 commits
dff945d
6ff78b0
9a2d421
c78130a
eab78e9
eade972
8723f00
5e9b2b4
891f022
e6b0d07
a438206
0a7e676
5792351
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { TryIt } from '../TryIt'; | |
type StackedLayoutProps = { | ||
uriMap: IUriMap; | ||
tree: ITableOfContents; | ||
bundledNodeData: unknown; | ||
}; | ||
|
||
type ItemRowProps = { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Cheating 😛 |
||
const groups = tree.items.filter(isGroup); | ||
|
||
return ( | ||
|
@@ -163,11 +164,21 @@ const ItemRow: React.FC<ItemRowProps> = ({ data, nodeType, type, title }) => { | |
onChange={(tabId: PanelTabId) => setTabId(tabId)} | ||
renderActiveTabPanelOnly | ||
> | ||
<Tab id="docs" title="Docs" className="p-4" panel={<Docs nodeType={nodeType} nodeData={data} headless />} /> | ||
<Tab id="tryit" title="Try It" className="p-4" panel={<TryIt nodeType={nodeType} nodeData={data} />} /> | ||
<Tab | ||
id="docs" | ||
title="Docs" | ||
className="p-4" | ||
panel={<Docs nodeType={nodeType} nodeData={bundledNodeData} headless />} | ||
/> | ||
<Tab | ||
id="tryit" | ||
title="Try It" | ||
className="p-4" | ||
panel={<TryIt nodeType={nodeType} nodeData={bundledNodeData} />} | ||
/> | ||
</Tabs> | ||
) : ( | ||
<Docs className="mx-auto p-4" nodeType={nodeType} nodeData={data} headless /> | ||
<Docs className="mx-auto p-4" nodeType={nodeType} nodeData={bundledNodeData} headless /> | ||
)} | ||
</Collapse> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(or We can leave it as well too, as I doubt function will ever be provided. |
||||||
import * as React from 'react'; | ||||||
|
||||||
import { useParsedData } from './useParsedData'; | ||||||
|
||||||
/** | ||||||
* @param type branch node snapshot type | ||||||
* @param data branch node snapshot data | ||||||
*/ | ||||||
|
||||||
interface Options { | ||||||
baseUrl?: string; | ||||||
} | ||||||
|
||||||
export function useBundledData(type: NodeType, data: unknown, options?: Options) { | ||||||
const parsedData = useParsedData(type, data); | ||||||
|
||||||
const [bundledData, setBundledData] = React.useState(parsedData); | ||||||
|
||||||
React.useEffect(() => { | ||||||
if (!isObject(parsedData) || type !== NodeType.HttpOperation) { | ||||||
setBundledData(parsedData); | ||||||
return; | ||||||
} | ||||||
|
||||||
doBundle(parsedData, options?.baseUrl) | ||||||
.then(res => setBundledData(res)) | ||||||
.catch(reason => { | ||||||
console.error(`Could not bundle: ${reason.message}`); | ||||||
console.error(reason); | ||||||
marcelltoth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
setBundledData(parsedData); | ||||||
}); | ||||||
}, [parsedData, type, options?.baseUrl]); | ||||||
|
||||||
return bundledData; | ||||||
} | ||||||
|
||||||
const commonBundleOptions = { continueOnError: true }; | ||||||
const doBundle = (data: object, baseUrl?: string) => { | ||||||
if (!baseUrl) { | ||||||
return $RefParser.bundle(data, commonBundleOptions); | ||||||
} else { | ||||||
return $RefParser.bundle(baseUrl, data, commonBundleOptions); | ||||||
} | ||||||
}; |
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.