Skip to content

Commit

Permalink
fix: constraints label details
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVarchuk committed May 30, 2022
1 parent 77104d6 commit eb0917d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/components/Fields/ArrayItemDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ import { ConstraintsView } from './FieldContstraints';
import { Pattern } from './Pattern';
import { SchemaModel } from '../../services';
import styled from '../../styled-components';
import { OptionsContext } from '../OptionsProvider';

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 (
<Wrapper>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Parameters/Parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export function BodyContent(props: {
return (
<>
{description !== undefined && <Markdown source={description} />}
<ConstraintsView constraints={schema?.constraints || []} />
{schema?.type === 'object' && (
<ConstraintsView constraints={schema?.constraints || []} />
)}
<Schema
skipReadOnly={isRequestType}
skipWriteOnly={!isRequestType}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Responses/ResponseDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class ResponseDetails extends React.PureComponent<{ response: ResponseMod
{({ schema }) => {
return (
<>
<ConstraintsView constraints={schema?.constraints || []} />
{schema?.type === 'object' && (
<ConstraintsView constraints={schema?.constraints || []} />
)}
<Schema skipWriteOnly={true} key="schema" schema={schema} />
</>
);
Expand Down

0 comments on commit eb0917d

Please sign in to comment.