mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-06 13:20:19 +03:00
Create nonce option to feed __webpack_nonce__
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
This commit is contained in:
parent
bccd21394e
commit
5fcb2656af
|
@ -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}>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user