Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hideRequestPayloadSample #2436

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading