mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Fix x-codeSamples: false not working at the single operation level (#2408)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix x-codeSamples: false not working at the single operation level
|
||||||
@@ -52,7 +52,7 @@ export function OpenAPICodeSample(props: {
|
|||||||
}> = null;
|
}> = null;
|
||||||
(['x-custom-examples', 'x-code-samples', 'x-codeSamples'] as const).forEach((key) => {
|
(['x-custom-examples', 'x-code-samples', 'x-codeSamples'] as const).forEach((key) => {
|
||||||
const customSamples = data.operation[key];
|
const customSamples = data.operation[key];
|
||||||
if (customSamples) {
|
if (customSamples && Array.isArray(customSamples)) {
|
||||||
customCodeSamples = customSamples.map((sample) => ({
|
customCodeSamples = customSamples.map((sample) => ({
|
||||||
key: `redocly-${sample.lang}`,
|
key: `redocly-${sample.lang}`,
|
||||||
label: sample.label,
|
label: sample.label,
|
||||||
@@ -61,7 +61,11 @@ export function OpenAPICodeSample(props: {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const samples = customCodeSamples ?? (data['x-codeSamples'] !== false ? autoCodeSamples : []);
|
// Code samples can be disabled at the top-level or at the operation level
|
||||||
|
// If code samples are defined at the operation level, it will override the top-level setting
|
||||||
|
const codeSamplesDisabled =
|
||||||
|
data['x-codeSamples'] === false || data.operation['x-codeSamples'] === false;
|
||||||
|
const samples = customCodeSamples ?? (!codeSamplesDisabled ? autoCodeSamples : []);
|
||||||
if (samples.length === 0) {
|
if (samples.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export interface OpenAPICustomSpecProperties {
|
|||||||
*/
|
*/
|
||||||
export interface OpenAPICustomOperationProperties {
|
export interface OpenAPICustomOperationProperties {
|
||||||
'x-code-samples'?: OpenAPICustomCodeSample[];
|
'x-code-samples'?: OpenAPICustomCodeSample[];
|
||||||
'x-codeSamples'?: OpenAPICustomCodeSample[];
|
'x-codeSamples'?: OpenAPICustomCodeSample[] | false;
|
||||||
'x-custom-examples'?: OpenAPICustomCodeSample[];
|
'x-custom-examples'?: OpenAPICustomCodeSample[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user