mirror of
https://github.com/Redocly/redoc.git
synced 2025-03-03 17:35:46 +03:00
feat: new option generatedPayloadSamplesMaxDepth (#1642)
This commit is contained in:
parent
1d088a8dd8
commit
bd9390a5bf
|
@ -105,6 +105,7 @@ You can use all of the following options with the standalone version of the <red
|
||||||
* `disableSearch` - disable search indexing and search box.
|
* `disableSearch` - disable search indexing and search box.
|
||||||
* `expandDefaultServerVariables` - enable expanding default server variables, default `false`.
|
* `expandDefaultServerVariables` - enable expanding default server variables, default `false`.
|
||||||
* `expandResponses` - specify which responses to expand by default by response codes. Values should be passed as comma-separated list without spaces e.g. `expandResponses="200,201"`. Special value `"all"` expands all responses by default. Be careful: this option can slow-down documentation rendering time.
|
* `expandResponses` - specify which responses to expand by default by response codes. Values should be passed as comma-separated list without spaces e.g. `expandResponses="200,201"`. Special value `"all"` expands all responses by default. Be careful: this option can slow-down documentation rendering time.
|
||||||
|
* `generatedPayloadSamplesMaxDepth` - set the maximum render depth for JSON payload samples (responses and request body). The default value is `10`.
|
||||||
* `maxDisplayedEnumValues` - display only specified number of enum values. hide rest values under spoiler.
|
* `maxDisplayedEnumValues` - display only specified number of enum values. hide rest values under spoiler.
|
||||||
* `hideDownloadButton` - do not show "Download" spec button. **THIS DOESN'T MAKE YOUR SPEC PRIVATE**, it just hides the button.
|
* `hideDownloadButton` - do not show "Download" spec button. **THIS DOESN'T MAKE YOUR SPEC PRIVATE**, it just hides the button.
|
||||||
* `hideHostname` - if set, the protocol and hostname is not shown in the operation definition.
|
* `hideHostname` - if set, the protocol and hostname is not shown in the operation definition.
|
||||||
|
|
|
@ -42,6 +42,7 @@ export interface RedocRawOptions {
|
||||||
maxDisplayedEnumValues?: number;
|
maxDisplayedEnumValues?: number;
|
||||||
ignoreNamedSchemas?: string[] | string;
|
ignoreNamedSchemas?: string[] | string;
|
||||||
hideSchemaPattern?: boolean;
|
hideSchemaPattern?: boolean;
|
||||||
|
generatedPayloadSamplesMaxDepth?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
|
export function argValueToBoolean(val?: string | boolean, defaultValue?: boolean): boolean {
|
||||||
|
@ -163,6 +164,16 @@ export class RedocNormalizedOptions {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static normalizeGeneratedPayloadSamplesMaxDepth(
|
||||||
|
value?: number | string | undefined,
|
||||||
|
): number {
|
||||||
|
if (!isNaN(Number(value))) {
|
||||||
|
return Math.max(0, Number(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
theme: ResolvedThemeInterface;
|
theme: ResolvedThemeInterface;
|
||||||
scrollYOffset: () => number;
|
scrollYOffset: () => number;
|
||||||
hideHostname: boolean;
|
hideHostname: boolean;
|
||||||
|
@ -196,6 +207,7 @@ export class RedocNormalizedOptions {
|
||||||
|
|
||||||
ignoreNamedSchemas: Set<string>;
|
ignoreNamedSchemas: Set<string>;
|
||||||
hideSchemaPattern: boolean;
|
hideSchemaPattern: boolean;
|
||||||
|
generatedPayloadSamplesMaxDepth: number;
|
||||||
|
|
||||||
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
|
constructor(raw: RedocRawOptions, defaults: RedocRawOptions = {}) {
|
||||||
raw = { ...defaults, ...raw };
|
raw = { ...defaults, ...raw };
|
||||||
|
@ -257,5 +269,9 @@ export class RedocNormalizedOptions {
|
||||||
: raw.ignoreNamedSchemas?.split(',').map((s) => s.trim());
|
: raw.ignoreNamedSchemas?.split(',').map((s) => s.trim());
|
||||||
this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
|
this.ignoreNamedSchemas = new Set(ignoreNamedSchemas);
|
||||||
this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
|
this.hideSchemaPattern = argValueToBoolean(raw.hideSchemaPattern);
|
||||||
|
this.generatedPayloadSamplesMaxDepth =
|
||||||
|
RedocNormalizedOptions.normalizeGeneratedPayloadSamplesMaxDepth(
|
||||||
|
raw.generatedPayloadSamplesMaxDepth,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ export class MediaTypeModel {
|
||||||
name: string;
|
name: string;
|
||||||
isRequestType: boolean;
|
isRequestType: boolean;
|
||||||
onlyRequiredInSamples: boolean;
|
onlyRequiredInSamples: boolean;
|
||||||
|
generatedPayloadSamplesMaxDepth: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param isRequestType needed to know if skipe RO/RW fields in objects
|
* @param isRequestType needed to know if skipe RO/RW fields in objects
|
||||||
|
@ -29,6 +30,7 @@ export class MediaTypeModel {
|
||||||
this.isRequestType = isRequestType;
|
this.isRequestType = isRequestType;
|
||||||
this.schema = info.schema && new SchemaModel(parser, info.schema, '', options);
|
this.schema = info.schema && new SchemaModel(parser, info.schema, '', options);
|
||||||
this.onlyRequiredInSamples = options.onlyRequiredInSamples;
|
this.onlyRequiredInSamples = options.onlyRequiredInSamples;
|
||||||
|
this.generatedPayloadSamplesMaxDepth = options.generatedPayloadSamplesMaxDepth;
|
||||||
if (info.examples !== undefined) {
|
if (info.examples !== undefined) {
|
||||||
this.examples = mapValues(
|
this.examples = mapValues(
|
||||||
info.examples,
|
info.examples,
|
||||||
|
@ -53,7 +55,7 @@ export class MediaTypeModel {
|
||||||
skipReadOnly: this.isRequestType,
|
skipReadOnly: this.isRequestType,
|
||||||
skipWriteOnly: !this.isRequestType,
|
skipWriteOnly: !this.isRequestType,
|
||||||
skipNonRequired: this.isRequestType && this.onlyRequiredInSamples,
|
skipNonRequired: this.isRequestType && this.onlyRequiredInSamples,
|
||||||
maxSampleDepth: 10,
|
maxSampleDepth: this.generatedPayloadSamplesMaxDepth,
|
||||||
};
|
};
|
||||||
if (this.schema && this.schema.oneOf) {
|
if (this.schema && this.schema.oneOf) {
|
||||||
this.examples = {};
|
this.examples = {};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user