diff --git a/src/components/RedocStandalone.tsx b/src/components/RedocStandalone.tsx index 40bf73cb..0f436558 100644 --- a/src/components/RedocStandalone.tsx +++ b/src/components/RedocStandalone.tsx @@ -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 ( diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index be1df279..2bd296ce 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -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; } }