-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathApiSchema.tsx
More file actions
51 lines (47 loc) · 1.3 KB
/
ApiSchema.tsx
File metadata and controls
51 lines (47 loc) · 1.3 KB
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
47
48
49
50
51
import React, { useEffect } from 'react';
import clsx from 'clsx';
import { ThemeProvider } from 'styled-components';
import '../../global';
import { SchemaDefinition } from 'redoc';
import { useSpec } from '../../utils/useSpec';
import { useSpecData } from '../useSpecData';
import type { ApiSchemaProps } from '../../types/common';
import '../Redoc/styles.css';
import './styles.css';
const ApiSchema: React.FC<ApiSchemaProps> = ({
id,
spec,
pointer,
showExample = false,
example = showExample,
...rest
}: ApiSchemaProps): React.JSX.Element => {
const specProps = useSpecData(id, spec);
const { store } = useSpec(specProps);
useEffect(() => {
/**
* @see https://github.com/Redocly/redoc/blob/823be24b313c3a2445df7e0801a0cc79c20bacd1/src/services/MenuStore.ts#L273-L276
*/
store.menu.dispose();
}, [store]);
return (
<ThemeProvider theme={store.options.theme}>
<div
className={clsx([
'redocusaurus',
'redocusaurus-schema',
example ? null : 'hide-example',
])}
>
<SchemaDefinition
parser={store.spec.parser}
options={store.options}
schemaRef={pointer}
showExample={example}
{...rest}
/>
</div>
</ThemeProvider>
);
};
export default ApiSchema;