Skip to content

Commit 7b1a882

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

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

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 {

packages/elements/src/containers/API.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,13 @@ export interface CommonAPIProps extends RoutingProps {
113113
tryItCorsProxy?: string;
114114

115115
/**
116-
* The amount of references deep should be presented.
116+
* Whether to include CORS credentials (cookies, authorization headers, TLS client certificates)
117+
* in remote ref requests
118+
* @default: false
119+
*/
120+
withCredentials?: boolean;
121+
122+
/** The amount of references deep should be presented.
117123
* @default undefined
118124
*/
119125
maxRefDepth?: number;
@@ -143,6 +149,7 @@ export const APIImpl: React.FC<APIProps> = props => {
143149
hideExport,
144150
tryItCredentialsPolicy,
145151
tryItCorsProxy,
152+
withCredentials,
146153
maxRefDepth,
147154
renderExtensionAddon,
148155
} = props;
@@ -166,7 +173,7 @@ export const APIImpl: React.FC<APIProps> = props => {
166173

167174
const document = apiDescriptionDocument || fetchedDocument || '';
168175
const parsedDocument = useParsedValue(document);
169-
const bundledDocument = useBundleRefsIntoDocument(parsedDocument, { baseUrl: apiDescriptionUrl });
176+
const bundledDocument = useBundleRefsIntoDocument(parsedDocument, { baseUrl: apiDescriptionUrl, withCredentials });
170177
const serviceNode = React.useMemo(() => transformOasToServiceNode(bundledDocument), [bundledDocument]);
171178
const exportProps = useExportDocumentProps({ originalDocument: document, bundledDocument });
172179

packages/elements/src/web-components/components.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const ApiElement = createElementClass(API, {
2020
logo: { type: 'string' },
2121
tryItCredentialsPolicy: { type: 'string' },
2222
tryItCorsProxy: { type: 'string' },
23+
withCredentials: { type: 'boolean' },
2324
maxRefDepth: { type: 'number' },
2425
renderExtensionAddon: { type: 'function' },
2526
});

0 commit comments

Comments
 (0)