import type { Operation } from './types' import { useTranslation } from 'components/hooks/useTranslation' import { CodeBlock } from './CodeBlock' import { getShellExample, getGHExample, getJSExample } from '../lib/get-rest-code-samples' type Props = { slug: string operation: Operation } export function RestCodeSamples({ operation, slug }: Props) { const { t } = useTranslation('products') const JAVASCRIPT_HEADING = ( JavaScript{' '} @octokit/core.js ) const GH_CLI_HEADING = ( GitHub CLI{' '} gh api ) // Format the example properties into different language examples const languageExamples = operation.codeExamples.map((sample) => { const languageExamples = { curl: getShellExample(operation, sample), javascript: getJSExample(operation, sample), ghcli: getGHExample(operation, sample), } return Object.assign({}, sample, languageExamples) }) return ( <>

{`${t('rest.reference.code_samples')}`}

{languageExamples.map((sample, index) => (
{/* Example requests */} {sample.request && ( <> {/* Title of the code sample block */}
{sample.curl && ( )} {sample.javascript && ( )} {sample.ghcli && ( )} )} {/* Title of the response */} {sample.response && ( <>
{/* Status code */} {sample.response.statusCode && ( )} {/* Example response */} {sample.response.example && ( )} )}
))} ) }