diff --git a/.changeset/spotty-apples-crash.md b/.changeset/spotty-apples-crash.md new file mode 100644 index 000000000..20aa75e6d --- /dev/null +++ b/.changeset/spotty-apples-crash.md @@ -0,0 +1,6 @@ +--- +'@gitbook/openapi-parser': patch +'@gitbook/react-openapi': patch +--- + +Optional label in OpenAPI x-codeSamples diff --git a/packages/openapi-parser/src/types.ts b/packages/openapi-parser/src/types.ts index fa5b6ade3..79a0b66ed 100644 --- a/packages/openapi-parser/src/types.ts +++ b/packages/openapi-parser/src/types.ts @@ -79,7 +79,7 @@ export type OpenAPIStability = 'experimental' | 'alpha' | 'beta'; */ export interface OpenAPICustomCodeSample { lang: string; - label: string; + label?: string; source: string; } diff --git a/packages/react-openapi/src/OpenAPICodeSample.tsx b/packages/react-openapi/src/OpenAPICodeSample.tsx index 8bffb6d9a..4e51d26ee 100644 --- a/packages/react-openapi/src/OpenAPICodeSample.tsx +++ b/packages/react-openapi/src/OpenAPICodeSample.tsx @@ -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,