-
Notifications
You must be signed in to change notification settings - Fork 30
/
PropValidations.tsx
46 lines (38 loc) · 1.14 KB
/
PropValidations.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { safeStringify } from '@stoplight/json';
import { ISchema } from '@stoplight/types';
import * as React from 'react';
import { isCombiner } from './util/isCombiner';
import { pickValidations } from './util/pickValidations';
import { MutedText } from './common/MutedText';
export const PropValidations: React.FunctionComponent<{ prop: ISchema }> = ({ prop }) => {
if (!isCombiner(prop)) {
const validations = pickValidations(prop);
return (
<>
{Object.entries(validations).map(([k, v]) => {
let type = typeof v;
if (k === 'default' && ['object', 'boolean'].includes(type)) {
v = safeStringify(v);
type = typeof v;
}
if (type === 'boolean') {
return (
<div key={k}>
<MutedText as="b">{k}:</MutedText> {v.toString()}
</div>
);
}
if (type !== 'object') {
return (
<div key={k}>
<MutedText as="b">{k}:</MutedText> {v}
</div>
);
}
return null;
})}
</>
);
}
return null;
};