Skip to content

Commit 994693a

Browse files
ellyx-csgwilliamsuryadgit
authored andcommitted
send credential when bundling $ref
based on this PR stoplightio#2006
1 parent 48f777a commit 994693a

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

Diff for: packages/elements-core/src/hooks/useBundleRefsIntoDocument.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as React from 'react';
99

1010
interface Options {
1111
baseUrl?: string;
12+
withCredentials?: boolean;
1213
}
1314

1415
/**
@@ -18,6 +19,7 @@ export function useBundleRefsIntoDocument(document: unknown, options?: Options)
1819
const [bundledData, setBundledData] = React.useState(document);
1920

2021
const baseUrl = options?.baseUrl;
22+
const withCredentials = options?.withCredentials;
2123

2224
React.useEffect(() => {
2325
if (!isObject(document)) {
@@ -26,7 +28,7 @@ export function useBundleRefsIntoDocument(document: unknown, options?: Options)
2628
}
2729

2830
let isMounted = true;
29-
doBundle(document, baseUrl)
31+
doBundle(document, baseUrl, withCredentials)
3032
.then(res => {
3133
if (isMounted) {
3234
setBundledData({ ...res }); // this hmm....library mutates document so a shallow copy is required to force a rerender in all cases
@@ -45,13 +47,18 @@ export function useBundleRefsIntoDocument(document: unknown, options?: Options)
4547
return () => {
4648
isMounted = false;
4749
};
48-
}, [document, baseUrl]);
50+
}, [document, baseUrl, withCredentials]);
4951

5052
return bundledData;
5153
}
5254

53-
const commonBundleOptions = { continueOnError: true };
54-
const doBundle = (data: object, baseUrl?: string) => {
55+
const doBundle = (data: object, baseUrl?: string, withCredentials?: boolean) => {
56+
const commonBundleOptions = {
57+
continueOnError: true,
58+
resolve: {
59+
http: <$RefParser.HTTPResolverOptions>{ withCredentials },
60+
},
61+
};
5562
if (!baseUrl) {
5663
return $RefParser.bundle(data, commonBundleOptions);
5764
} else {

Diff for: packages/elements/src/containers/API.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ export interface CommonAPIProps extends RoutingProps {
122122
* Allows to define renderers for vendor extensions
123123
*/
124124
renderExtensionAddon?: ExtensionAddonRenderer;
125+
126+
/**
127+
* Whether to include CORS credentials (cookies, authorization headers, TLS client certificates)
128+
* in remote ref requests
129+
* @default: false
130+
*/
131+
withCredentials?: boolean;
125132
}
126133

127134
const propsAreWithDocument = (props: APIProps): props is APIPropsWithDocument => {
@@ -145,6 +152,7 @@ export const APIImpl: React.FC<APIProps> = props => {
145152
tryItCorsProxy,
146153
maxRefDepth,
147154
renderExtensionAddon,
155+
withCredentials,
148156
} = props;
149157
const location = useLocation();
150158
const apiDescriptionDocument = propsAreWithDocument(props) ? props.apiDescriptionDocument : undefined;
@@ -166,7 +174,7 @@ export const APIImpl: React.FC<APIProps> = props => {
166174

167175
const document = apiDescriptionDocument || fetchedDocument || '';
168176
const parsedDocument = useParsedValue(document);
169-
const bundledDocument = useBundleRefsIntoDocument(parsedDocument, { baseUrl: apiDescriptionUrl });
177+
const bundledDocument = useBundleRefsIntoDocument(parsedDocument, { baseUrl: apiDescriptionUrl, withCredentials });
170178
const serviceNode = React.useMemo(() => transformOasToServiceNode(bundledDocument), [bundledDocument]);
171179
const exportProps = useExportDocumentProps({ originalDocument: document, bundledDocument });
172180

Diff for: packages/elements/src/web-components/components.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export const ApiElement = createElementClass(API, {
2222
tryItCorsProxy: { type: 'string' },
2323
maxRefDepth: { type: 'number' },
2424
renderExtensionAddon: { type: 'function' },
25+
withCredentials: { type: 'boolean' },
2526
});

0 commit comments

Comments
 (0)