From 8c651361297a5f8eba9bfb8613651fe13d6c041f Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Mon, 23 Oct 2023 18:36:53 +0300 Subject: [PATCH] fix: hideRequestPayloadSample (#2436) --- .../__snapshots__/DiscriminatorDropdown.test.tsx.snap | 10 ++++++++++ src/services/RedocNormalizedOptions.ts | 3 +++ src/services/models/Operation.ts | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap b/src/components/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap index 751580766a..c47b6f3746 100644 --- a/src/components/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap @@ -87,6 +87,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -376,6 +377,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -652,6 +654,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -990,6 +993,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -1291,6 +1295,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -1563,6 +1568,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -1860,6 +1866,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -2187,6 +2194,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -2476,6 +2484,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -2752,6 +2761,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index 4ff1ec76a0..fd162b91d0 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -28,6 +28,7 @@ export interface RedocRawOptions { showExtensions?: boolean | string | string[]; sideNavStyle?: SideNavStyleEnum; hideSingleRequestSampleTab?: boolean | string; + hideRequestPayloadSample?: boolean; menuToggle?: boolean | string; jsonSampleExpandLevel?: number | string | 'all'; hideSchemaTitles?: boolean | string; @@ -231,6 +232,7 @@ export class RedocNormalizedOptions { showExtensions: boolean | string[]; sideNavStyle: SideNavStyleEnum; hideSingleRequestSampleTab: boolean; + hideRequestPayloadSample: boolean; menuToggle: boolean; jsonSampleExpandLevel: number; enumSkipQuotes: boolean; @@ -302,6 +304,7 @@ export class RedocNormalizedOptions { this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions); this.sideNavStyle = RedocNormalizedOptions.normalizeSideNavStyle(raw.sideNavStyle); this.hideSingleRequestSampleTab = argValueToBoolean(raw.hideSingleRequestSampleTab); + this.hideRequestPayloadSample = argValueToBoolean(raw.hideRequestPayloadSample); this.menuToggle = argValueToBoolean(raw.menuToggle, true); this.jsonSampleExpandLevel = RedocNormalizedOptions.normalizeJsonSampleExpandLevel( raw.jsonSampleExpandLevel, diff --git a/src/services/models/Operation.ts b/src/services/models/Operation.ts index 96fbb43aa3..9af57acba1 100644 --- a/src/services/models/Operation.ts +++ b/src/services/models/Operation.ts @@ -202,6 +202,7 @@ export class OperationModel implements IMenuItem { @memoize get codeSamples() { + const { payloadSampleIdx, hideRequestPayloadSample } = this.options; let samples: Array = this.operationSpec['x-codeSamples'] || this.operationSpec['x-code-samples'] || []; @@ -211,8 +212,8 @@ export class OperationModel implements IMenuItem { } const requestBodyContent = this.requestBody && this.requestBody.content; - if (requestBodyContent && requestBodyContent.hasSample) { - const insertInx = Math.min(samples.length, this.options.payloadSampleIdx); + if (requestBodyContent && requestBodyContent.hasSample && !hideRequestPayloadSample) { + const insertInx = Math.min(samples.length, payloadSampleIdx); samples = [ ...samples.slice(0, insertInx),