fix: constraints label details

This commit is contained in:
Alex Varchuk 2022-05-20 10:44:02 +03:00
parent 77104d6c0d
commit eb0917d002
3 changed files with 18 additions and 3 deletions

View File

@ -4,9 +4,20 @@ import { ConstraintsView } from './FieldContstraints';
import { Pattern } from './Pattern'; import { Pattern } from './Pattern';
import { SchemaModel } from '../../services'; import { SchemaModel } from '../../services';
import styled from '../../styled-components'; import styled from '../../styled-components';
import { OptionsContext } from '../OptionsProvider';
export function ArrayItemDetails({ schema }: { schema: SchemaModel }) { export function ArrayItemDetails({ schema }: { schema: SchemaModel }) {
if (!schema || (schema.type === 'string' && !schema.constraints.length)) return null; const { hideSchemaPattern } = React.useContext(OptionsContext);
if (
!schema ||
(schema.type === 'string' && !schema.constraints.length) ||
((!schema?.pattern || hideSchemaPattern) &&
!schema.items &&
!schema.displayFormat &&
!schema.constraints.length)
) {
return null;
}
return ( return (
<Wrapper> <Wrapper>

View File

@ -80,7 +80,9 @@ export function BodyContent(props: {
return ( return (
<> <>
{description !== undefined && <Markdown source={description} />} {description !== undefined && <Markdown source={description} />}
{schema?.type === 'object' && (
<ConstraintsView constraints={schema?.constraints || []} /> <ConstraintsView constraints={schema?.constraints || []} />
)}
<Schema <Schema
skipReadOnly={isRequestType} skipReadOnly={isRequestType}
skipWriteOnly={!isRequestType} skipWriteOnly={!isRequestType}

View File

@ -24,7 +24,9 @@ export class ResponseDetails extends React.PureComponent<{ response: ResponseMod
{({ schema }) => { {({ schema }) => {
return ( return (
<> <>
{schema?.type === 'object' && (
<ConstraintsView constraints={schema?.constraints || []} /> <ConstraintsView constraints={schema?.constraints || []} />
)}
<Schema skipWriteOnly={true} key="schema" schema={schema} /> <Schema skipWriteOnly={true} key="schema" schema={schema} />
</> </>
); );