mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +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) => {
|
||||
const customSamples = data.operation[key];
|
||||
if (customSamples && Array.isArray(customSamples)) {
|
||||
customCodeSamples = customSamples.map((sample) => ({
|
||||
key: `redocly-${sample.lang}`,
|
||||
label: sample.label,
|
||||
body: <context.CodeBlock code={sample.source} syntax={sample.lang} />,
|
||||
}));
|
||||
customCodeSamples = customSamples
|
||||
.filter((sample) => {
|
||||
return (
|
||||
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);
|
||||
if (example === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
key: `${response[0]}`,
|
||||
label: `${response[0]}`,
|
||||
|
||||
Reference in New Issue
Block a user