mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +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 {
|
export interface OpenAPICustomCodeSample {
|
||||||
lang: string;
|
lang: string;
|
||||||
label: string;
|
label?: string;
|
||||||
source: string;
|
source: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -253,15 +253,11 @@ function getCustomCodeSamples(props: {
|
|||||||
if (customSamples && Array.isArray(customSamples)) {
|
if (customSamples && Array.isArray(customSamples)) {
|
||||||
customCodeSamples = customSamples
|
customCodeSamples = customSamples
|
||||||
.filter((sample) => {
|
.filter((sample) => {
|
||||||
return (
|
return typeof sample.source === 'string' && typeof sample.lang === 'string';
|
||||||
typeof sample.label === 'string' &&
|
|
||||||
typeof sample.source === 'string' &&
|
|
||||||
typeof sample.lang === 'string'
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.map((sample, index) => ({
|
.map((sample, index) => ({
|
||||||
key: `custom-sample-${sample.lang}-${index}`,
|
key: `custom-sample-${sample.lang}-${index}`,
|
||||||
label: sample.label,
|
label: sample.label || sample.lang,
|
||||||
body: context.renderCodeBlock({
|
body: context.renderCodeBlock({
|
||||||
code: sample.source,
|
code: sample.source,
|
||||||
syntax: sample.lang,
|
syntax: sample.lang,
|
||||||
|
|||||||
Reference in New Issue
Block a user