From bf960612a47bfe10ff205b9d78f3040515a5467d 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 5f865af57e..31e0327d9e 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, @@ -358,6 +359,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -616,6 +618,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -936,6 +939,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -1219,6 +1223,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -1473,6 +1478,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -1752,6 +1758,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -2061,6 +2068,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -2332,6 +2340,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView "hideDownloadButton": false, "hideFab": false, "hideHostname": false, + "hideRequestPayloadSample": false, "hideSchemaPattern": false, "hideSchemaTitles": false, "hideSecuritySection": false, @@ -2590,6 +2599,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 4a219eef16..0cdd7f9e2a 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 e26b4a4c19..f0a3a7852e 100644 --- a/src/services/models/Operation.ts +++ b/src/services/models/Operation.ts @@ -195,6 +195,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'] || []; @@ -204,8 +205,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),