From 54a7ff9fe7d34abe034028b2daff8b0577594d07 Mon Sep 17 00:00:00 2001 From: gary-Shen Date: Mon, 26 Feb 2024 19:19:28 +0800 Subject: [PATCH] docs: add pre annoation schema --- src/components/schema-table/index.tsx | 61 +- src/locale/resources/en-US.json | 8 +- src/locale/resources/zh-CN.json | 7 +- .../guide.introduction/markdown_en-US.mdx | 3 +- .../guide.introduction/markdown_zh-CN.mdx | 1 + src/pages/schema.audio.frame/example.mdx | 9 - src/pages/schema.audio.frame/schema.json | 3 +- src/pages/schema.audio.segment/example.mdx | 12 +- src/pages/schema.audio.segment/schema.json | 3 +- src/pages/schema.image.cuboid/schema.json | 9 +- src/pages/schema.image.line/example.mdx | 24 - src/pages/schema.image.line/schema.json | 6 + src/pages/schema.image.point/schema.json | 9 +- src/pages/schema.image.polygon/schema.json | 9 +- src/pages/schema.image.rect/example.mdx | 10 - src/pages/schema.image.rect/schema.json | 9 +- .../schema.pre-annotation.audio/example.mdx | 87 ++ .../schema.pre-annotation.audio/index.tsx | 11 + .../schema.pre-annotation.audio/schema.json | 818 ++++++++++++++++ .../schema.pre-annotation.image/example.mdx | 103 ++ .../schema.pre-annotation.image/index.tsx | 11 + .../schema.pre-annotation.image/schema.json | 900 ++++++++++++++++++ .../schema.pre-annotation.video/example.mdx | 86 ++ .../schema.pre-annotation.video/index.tsx | 11 + .../schema.pre-annotation.video/schema.json | 818 ++++++++++++++++ .../example.mdx | 23 + .../schema.reference.tag-attribute/index.tsx | 11 + .../schema.json | 46 + .../example.mdx | 19 + .../schema.reference.text-attribute/index.tsx | 11 + .../schema.json | 40 + src/pages/schema.tag/example.mdx | 24 + src/pages/schema.tag/index.tsx | 11 + src/pages/schema.tag/schema.json | 29 + src/pages/schema.text/example.mdx | 22 + src/pages/schema.text/index.tsx | 11 + src/pages/schema.text/schema.json | 29 + src/pages/schema.video.frame/example.mdx | 9 - src/pages/schema.video.frame/schema.json | 3 +- src/pages/schema.video.segment/example.mdx | 12 +- src/pages/schema.video.segment/schema.json | 3 +- src/routes.tsx | 92 ++ 42 files changed, 3327 insertions(+), 96 deletions(-) create mode 100644 src/pages/schema.pre-annotation.audio/example.mdx create mode 100644 src/pages/schema.pre-annotation.audio/index.tsx create mode 100644 src/pages/schema.pre-annotation.audio/schema.json create mode 100644 src/pages/schema.pre-annotation.image/example.mdx create mode 100644 src/pages/schema.pre-annotation.image/index.tsx create mode 100644 src/pages/schema.pre-annotation.image/schema.json create mode 100644 src/pages/schema.pre-annotation.video/example.mdx create mode 100644 src/pages/schema.pre-annotation.video/index.tsx create mode 100644 src/pages/schema.pre-annotation.video/schema.json create mode 100644 src/pages/schema.reference.tag-attribute/example.mdx create mode 100644 src/pages/schema.reference.tag-attribute/index.tsx create mode 100644 src/pages/schema.reference.tag-attribute/schema.json create mode 100644 src/pages/schema.reference.text-attribute/example.mdx create mode 100644 src/pages/schema.reference.text-attribute/index.tsx create mode 100644 src/pages/schema.reference.text-attribute/schema.json create mode 100644 src/pages/schema.tag/example.mdx create mode 100644 src/pages/schema.tag/index.tsx create mode 100644 src/pages/schema.tag/schema.json create mode 100644 src/pages/schema.text/example.mdx create mode 100644 src/pages/schema.text/index.tsx create mode 100644 src/pages/schema.text/schema.json diff --git a/src/components/schema-table/index.tsx b/src/components/schema-table/index.tsx index 321a9ccc..9d5f1703 100644 --- a/src/components/schema-table/index.tsx +++ b/src/components/schema-table/index.tsx @@ -1,4 +1,5 @@ import { useState, type FC } from 'react'; +import { Link } from 'react-router-dom'; import { BiChevronRight } from '@react-icons/all-files/bi/BiChevronRight'; import { BiChevronDown } from '@react-icons/all-files/bi/BiChevronDown'; import clsx from 'clsx'; @@ -7,10 +8,11 @@ import { useTranslation } from 'react-i18next'; interface SchemaProp { [key: string]: { required?: string[]; + $ref?: string; type: string | string[]; description?: string; default?: string | number | boolean; - items?: { properties: SchemaProp }; + items?: { properties: SchemaProp, $ref?: string, anyOf?: SchemaProp[]}; properties?: SchemaProp; additionalProperties?: { anyOf?: SchemaProp[]; @@ -23,18 +25,48 @@ const typeBadgeMap = { boolean: 'badge-error', array: 'badge-primary', object: 'badge-neutral', + null: 'badge-neutral', } as Record; interface Schema { type: 'object'; properties: SchemaProp; required: string[]; + definitions: SchemaProp; } interface JsonSchemaTableProps { schema: Schema; } +// #/definitions/TextAttribute -> text-attribute +function getReferenceName(ref: string) { + return ref.split('/').pop()!.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); +} + +function makeReferenceUrl(ref: string) { + return `/schema/reference/${getReferenceName(ref)}`; +} + +const resolveRef = (ref: string, definitions: SchemaProp | undefined) => { + if (!definitions || !ref.startsWith('#/definitions/')) { + return null; + } + + const path = ref.slice('#/definitions/'.length).split('/'); + let schema: SchemaProp | undefined = definitions; + + for (const segment of path) { + schema = schema[segment] as unknown as SchemaProp; + + if (!schema) { + break; + } + } + + return schema; +}; + const JsonSchemaTable: FC = ({ schema }) => { const { t } = useTranslation(); const headers = [t('field'), t('type'), t('required'), t('default'), t('description')]; @@ -68,6 +100,8 @@ const JsonSchemaTable: FC = ({ schema }) => {
{key} {((value.type === 'array' && value.items?.properties) || + (value.type === 'array' && value.items?.$ref) || + value.$ref || (value.type === 'object' && (value.properties || value.additionalProperties))) && (