Create nonce option to feed __webpack_nonce__

Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
This commit is contained in:
Quentin Devos 2021-04-03 23:37:21 +02:00
parent bccd21394e
commit 5fcb2656af
No known key found for this signature in database
GPG Key ID: 58B4FB3465174DAF
2 changed files with 11 additions and 0 deletions

View File

@ -13,12 +13,18 @@ export interface RedocStandaloneProps {
onLoaded?: (e?: Error) => any;
}
declare let __webpack_nonce__: string;
export const RedocStandalone = function (props: RedocStandaloneProps) {
const { spec, specUrl, options = {}, onLoaded } = props;
const hideLoading = argValueToBoolean(options.hideLoading, false);
const normalizedOpts = new RedocNormalizedOptions(options);
if (normalizedOpts.nonce !== undefined) {
__webpack_nonce__ = normalizedOpts.nonce;
}
return (
<ErrorBoundary>
<StoreBuilder spec={spec} specUrl={specUrl} options={options} onLoaded={onLoaded}>

View File

@ -43,6 +43,7 @@ export interface RedocRawOptions {
ignoreNamedSchemas?: string[] | string;
hideSchemaPattern?: boolean;
generatedPayloadSamplesMaxDepth?: number;
nonce?: string;
}
export function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
@ -209,6 +210,8 @@ export class RedocNormalizedOptions {
hideSchemaPattern: boolean;
generatedPayloadSamplesMaxDepth: number;
nonce?: string;
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
raw = { ...defaults, ...raw };
const hook = raw.theme && raw.theme.extensionsHook;
@ -273,5 +276,7 @@ export class RedocNormalizedOptions {
RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth(
raw.generatedPayloadSamplesMaxDepth,
);
this.nonce = raw.nonce;
}
}