import * as React from 'react'; import { observer } from 'mobx-react'; import { RecursiveLabel, TypeFormat, TypeName, TypePrefix, TypeTitle, } from '../../common-elements/fields'; import { getSerializedValue, isArray, isObject } from '../../utils'; import { ExternalDocumentation } from '../ExternalDocumentation/ExternalDocumentation'; import { Markdown } from '../Markdown/Markdown'; import { EnumValues } from './EnumValues'; import { Extensions } from './Extensions'; import { FieldProps } from './Field'; import { Examples } from './Examples'; import { ConstraintsView } from './FieldConstraints'; import { FieldDetail } from './FieldDetail'; import { Badge } from '../../common-elements/'; import { l } from '../../services/Labels'; import { OptionsContext } from '../OptionsProvider'; import { Pattern } from './Pattern'; import { ArrayItemDetails } from './ArrayItemDetails'; export const FieldDetailsComponent = observer((props: FieldProps) => { const { enumSkipQuotes, hideSchemaTitles } = React.useContext(OptionsContext); const { showExamples, field, renderDiscriminatorSwitch } = props; const { schema, description, deprecated, extensions, in: _in, const: _const } = field; const isArrayType = schema.type === 'array' || (isArray(schema.type) && schema.type.includes('array')); const rawDefault = enumSkipQuotes || _in === 'header'; // having quotes around header field default values is confusing and inappropriate const renderedExamples = React.useMemo(() => { if (showExamples && (field.example !== undefined || field.examples !== undefined)) { if (field.examples !== undefined) { return ; } else { return ( ); } } return null; }, [field, showExamples]); const defaultValue = isObject(schema.default) && field.in ? getSerializedValue(field, schema.default).replace(`${field.name}=`, '') : schema.default; return (
{schema.typePrefix} {schema.displayType} {schema.displayFormat && ( {' '} < {schema.displayFormat} >{' '} )} {schema.contentEncoding && ( {' '} < {schema.contentEncoding} >{' '} )} {schema.contentMediaType && ( {' '} < {schema.contentMediaType} >{' '} )} {schema.title && !hideSchemaTitles && ({schema.title}) } {schema.isCircular && {l('recursive')} } {isArrayType && schema.items && }
{deprecated && (
{l('deprecated')}
)} {!renderDiscriminatorSwitch && ( )}{' '} {renderedExamples}
{schema.externalDocs && ( )} {(renderDiscriminatorSwitch && renderDiscriminatorSwitch(props)) || null} {(_const && ) || null}
); }); export const FieldDetails = React.memo(FieldDetailsComponent);