diff --git a/README.md b/README.md index b02a5c97..bc5155a6 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,7 @@ You can use all of the following options with the standalone version of the 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) { + try { + __webpack_nonce__ = normalizedOpts.nonce; + } catch { } // If we have exception, Webpack was not used to run this. + } + return ( diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index 9d1c9ac6..3d5c65e7 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -54,6 +54,7 @@ export interface RedocRawOptions { ignoreNamedSchemas?: string[] | string; hideSchemaPattern?: boolean; generatedPayloadSamplesMaxDepth?: number; + nonce?: string; hideFab?: boolean; } @@ -251,6 +252,8 @@ export class RedocNormalizedOptions { generatedPayloadSamplesMaxDepth: number; hideFab: boolean; + nonce?: string; + constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) { raw = { ...defaults, ...raw }; const hook = raw.theme && raw.theme.extensionsHook; @@ -320,6 +323,7 @@ export class RedocNormalizedOptions { RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth( raw.generatedPayloadSamplesMaxDepth, ); + this.nonce = raw.nonce; this.hideFab = argValueToBoolean(raw.hideFab); } }