import cx from 'classnames' import { useTranslation } from 'components/hooks/useTranslation' import { BodyParameter, ChildParameter, ChildParamsGroup, Parameter, xGitHub } from './types' import styles from './RestParameterTable.module.scss' type Props = { slug: string hasRequiredPreviews: boolean xGitHub: xGitHub parameters: Array bodyParameters: Array } let nestedChildParamsRowIndex = 0 export function RestParameterTable({ slug, hasRequiredPreviews, xGitHub, parameters, bodyParameters, }: Props) { const { t } = useTranslation('products') const tableRows: JSX.Element[] = [] function addPreviewsRow() { tableRows.push( /* Previews require an `accept` header. These used to be documented as `operation.parameters` but have moved to `operation.x-github.previews` */ accept string header {hasRequiredPreviews ? (

This API is under preview and subject to change.

) : (

Setting to application/vnd.github.v3+json is recommended. {xGitHub.previews && ( {xGitHub.previews.length > 1 ? ` ${t('rest.reference.see_preview_notices')}` : ` ${t('rest.reference.see_preview_notice')}`} )}

)} ) } function addParametersRows(parameters: Parameter[]) { parameters.forEach((param: Parameter, index: number) => { tableRows.push( {param.name} {param.schema.type} {param.in}
{param.schema.default && (

Default: {param.schema.default}

)} ) }) } function addBodyParametersRows(bodyParameters: BodyParameter[]) { bodyParameters.forEach((bodyParam: BodyParameter, index: number) => { tableRows.push( {bodyParam.name} {bodyParam.type} {bodyParam.in}
{bodyParam.default && (

Default: {bodyParam.default}

)} ) // Adding the nested rows if (bodyParam.childParamsGroups && bodyParam.childParamsGroups.length > 0) { tableRows.push( {bodyParam.childParamsGroups.map( (childParamGroup: ChildParamsGroup, index: number) => { return (
{childParamGroup.params.map( (childParam: ChildParameter, index: number) => { return ( ) } )}
Name (Type) Description
{childParam.name} ({childParam.type})
) } )} ) nestedChildParamsRowIndex++ } }) } function renderTableRows() { addPreviewsRow() addParametersRows(parameters) addBodyParametersRows(bodyParameters) return tableRows } return ( <>

{t('rest.reference.parameters')}

{renderTableRows()}
Name Type In Description
) }