Skip to content

Commit

Permalink
fix: hideRequestPayloadSample
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk committed Oct 22, 2023
1 parent f28a807 commit ee0083a
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 @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
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 @@ -195,6 +195,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 @@ -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),
Expand Down

0 comments on commit ee0083a

Please sign in to comment.