Skip to content

Commit

Permalink
fix: hideRequestPayloadSample (Redocly#2436)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk authored and ckoegel committed Nov 1, 2023
1 parent fec880b commit 8c65136
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/services/RedocNormalizedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -231,6 +232,7 @@ export class RedocNormalizedOptions {
showExtensions: boolean | string[];
sideNavStyle: SideNavStyleEnum;
hideSingleRequestSampleTab: boolean;
hideRequestPayloadSample: boolean;
menuToggle: boolean;
jsonSampleExpandLevel: number;
enumSkipQuotes: boolean;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/services/models/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class OperationModel implements IMenuItem {

@memoize
get codeSamples() {
const { payloadSampleIdx, hideRequestPayloadSample } = this.options;
let samples: Array<OpenAPIXCodeSample | XPayloadSample> =
this.operationSpec['x-codeSamples'] || this.operationSpec['x-code-samples'] || [];

Expand All @@ -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),
Expand Down

0 comments on commit 8c65136

Please sign in to comment.