From 1e013cd87c5e6db6dc65b408cca58e726be064e6 Mon Sep 17 00:00:00 2001 From: "Nolann B." <100787331+nolannbiron@users.noreply.github.com> Date: Mon, 23 Jun 2025 13:54:15 +0200 Subject: [PATCH] Optional label in OpenAPI x-codeSamples (#3376) --- .changeset/spotty-apples-crash.md | 6 ++++++ packages/openapi-parser/src/types.ts | 2 +- packages/react-openapi/src/OpenAPICodeSample.tsx | 8 ++------ 3 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 .changeset/spotty-apples-crash.md 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,