Files
supabase/apps/docs/components/ApiSchema.tsx
Charis cf3ecc93eb chore(docs): turn on strictNullChecks (#36180)
strictNullChecks was off for docs, which lets errors slip through and
leads to incorrect required/optional typing on Zod-inferred types. This
PR enables strictNullChecks and fixes all the existing violations.
2025-06-04 17:05:37 -04:00

39 lines
1.0 KiB
TypeScript

import { sample } from '@har-sdk/openapi-sampler'
import { CodeBlock } from '~/features/ui/CodeBlock/CodeBlock'
import { Tabs, TabPanel } from '~/features/ui/Tabs'
type IParamProps = any
const ApiSchema = ({ schema, id }: IParamProps) => {
let example: string | undefined
try {
example = sample(schema, { skipReadOnly: true, quiet: true })
} catch {
example = undefined
}
return (
<Tabs
scrollable
size="small"
type="underlined"
defaultActiveId={example ? 'example' : 'schema'}
>
{example && (
<TabPanel key={`${id ?? ''}-example`} id="example" label="example">
<div className="mt-8">
<CodeBlock lang="bash">{JSON.stringify(example, null, 2)}</CodeBlock>
</div>
</TabPanel>
)}
<TabPanel key={`${id ?? ''}-schema`} id="schema" label="schema">
<div className="mt-8">
<CodeBlock lang="bash">{JSON.stringify(schema, null, 2)}</CodeBlock>
</div>
</TabPanel>
</Tabs>
)
}
export default ApiSchema