MCPcopy Index your code
hub / github.com/GitbookIO/gitbook / getCustomCodeSamples

Function getCustomCodeSamples

packages/react-openapi/src/OpenAPICodeSample.tsx:257–291  ·  view source on GitHub ↗

* Get custom code samples for the operation.

(props: {
    data: OpenAPIOperationData;
    context: OpenAPIContext;
})

Source from the content-addressed store, hash-verified

255 * Get custom code samples for the operation.
256 */
257function getCustomCodeSamples(props: {
258 data: OpenAPIOperationData;
259 context: OpenAPIContext;
260}) {
261 const { data, context } = props;
262
263 let customCodeSamples: null | Array<{
264 key: string;
265 label: string;
266 body: React.ReactNode;
267 }> = null;
268
269 CUSTOM_CODE_SAMPLES_KEYS.forEach((key) => {
270 const customSamples = data.operation[key];
271 if (customSamples && Array.isArray(customSamples)) {
272 customCodeSamples = customSamples
273 .filter((sample) => {
274 return typeof sample.source === 'string' && typeof sample.lang === 'string';
275 })
276 .map((sample, index) => ({
277 key: `custom-sample-${sample.lang}-${index}`,
278 label: sample.label || sample.lang,
279 body: context.renderCodeBlock({
280 code: sample.source,
281 syntax: sample.lang,
282 }),
283 footer: (
284 <OpenAPICodeSampleFooter renderers={[]} data={data} context={context} />
285 ),
286 }));
287 }
288 });
289
290 return customCodeSamples;
291}
292
293function getSecurityHeaders(args: {
294 securityRequirement: OpenAPIV3.OperationObject['security'];

Callers 1

OpenAPICodeSampleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected