Optional label in OpenAPI x-codeSamples (#3376)

This commit is contained in:
Nolann B.
2025-06-23 13:54:15 +02:00
committed by GitHub
parent f033734308
commit 1e013cd87c
3 changed files with 9 additions and 7 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@gitbook/openapi-parser': patch
'@gitbook/react-openapi': patch
---
Optional label in OpenAPI x-codeSamples
+1 -1
View File
@@ -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,