mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Fix crash in OpenAPI block because of undefined examples (#2458)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix crash when `example` is undefined for a response
|
||||||
@@ -69,11 +69,19 @@ export function OpenAPICodeSample(props: {
|
|||||||
(['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 && Array.isArray(customSamples)) {
|
if (customSamples && Array.isArray(customSamples)) {
|
||||||
customCodeSamples = customSamples.map((sample) => ({
|
customCodeSamples = customSamples
|
||||||
key: `redocly-${sample.lang}`,
|
.filter((sample) => {
|
||||||
label: sample.label,
|
return (
|
||||||
body: <context.CodeBlock code={sample.source} syntax={sample.lang} />,
|
typeof sample.label === 'string' &&
|
||||||
}));
|
typeof sample.source === 'string' &&
|
||||||
|
typeof sample.lang === 'string'
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.map((sample) => ({
|
||||||
|
key: `redocly-${sample.lang}`,
|
||||||
|
label: sample.label,
|
||||||
|
body: <context.CodeBlock code={sample.source} syntax={sample.lang} />,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ export function OpenAPIResponseExample(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const example = generateSchemaExample(schema);
|
const example = generateSchemaExample(schema);
|
||||||
|
if (example === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: `${response[0]}`,
|
key: `${response[0]}`,
|
||||||
label: `${response[0]}`,
|
label: `${response[0]}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user