mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Optional label in OpenAPI x-codeSamples (#3376)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@gitbook/openapi-parser': patch
|
||||
'@gitbook/react-openapi': patch
|
||||
---
|
||||
|
||||
Optional label in OpenAPI x-codeSamples
|
||||
@@ -79,7 +79,7 @@ export type OpenAPIStability = 'experimental' | 'alpha' | 'beta';
|
||||
*/
|
||||
export interface OpenAPICustomCodeSample {
|
||||
lang: string;
|
||||
label: string;
|
||||
label?: string;
|
||||
source: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -253,15 +253,11 @@ function getCustomCodeSamples(props: {
|
||||
if (customSamples && Array.isArray(customSamples)) {
|
||||
customCodeSamples = customSamples
|
||||
.filter((sample) => {
|
||||
return (
|
||||
typeof sample.label === 'string' &&
|
||||
typeof sample.source === 'string' &&
|
||||
typeof sample.lang === 'string'
|
||||
);
|
||||
return typeof sample.source === 'string' && typeof sample.lang === 'string';
|
||||
})
|
||||
.map((sample, index) => ({
|
||||
key: `custom-sample-${sample.lang}-${index}`,
|
||||
label: sample.label,
|
||||
label: sample.label || sample.lang,
|
||||
body: context.renderCodeBlock({
|
||||
code: sample.source,
|
||||
syntax: sample.lang,
|
||||
|
||||
Reference in New Issue
Block a user