Skip to content

Commit

Permalink
feat: resolve $ref
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-mt committed Dec 8, 2024
1 parent 235301c commit 7692287
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 16 deletions.
166 changes: 158 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@
},
"dependencies": {
"@ant-design/icons": "^5.3.7",
"@apidevtools/json-schema-ref-parser": "^11.7.3",
"@monaco-editor/react": "^4.6.0",
"antd": "^5.22.2",
"json-schema-library": "^10.0.0-rc5",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
20 changes: 12 additions & 8 deletions src/JsonSchemaEditor/SchemaItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ import {
theme,
Tooltip,
} from 'antd';
import { Draft07 } from 'json-schema-library';
import _ from 'lodash';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import MonacoEditor from '../MonacoEditor';
import { JSONSchema7 } from '../types';
import {
getDefaultSchema,
getPropertyIndex,
inferSchema,
parseJsonStr,
resolveJsonSchemaRef,
SchemaTypeOptions,
SchemaTypes,
StringFormat,
Expand Down Expand Up @@ -154,6 +156,10 @@ function SchemaItem(props: SchemaItemProps) {
!isArrayItems &&
!isRoot;

if (!schema.type) {
return <></>;
}

return (
<>
{contextHolder}
Expand Down Expand Up @@ -779,25 +785,23 @@ function SchemaItem(props: SchemaItemProps) {
okText={'导入'}
cancelText={'取消'}
open={importModal}
onOk={() => {
onOk={async () => {
if (!importValue || importValue.length === 0) {
messageApi.warning('请输入导入的 Json 数据');
return;
}
let importJson;
try {
importJson = JSON.parse(importValue);
} catch (e) {
const importObject = parseJsonStr(importValue);
if (!importObject) {
messageApi.error('导入的内容不是 Json 格式的数据');
return;
}
let schema;
switch (importType) {
case 'json':
schema = inferSchema(importJson);
schema = new Draft07().createSchemaOf(importObject);
break;
case 'json-schema':
schema = importJson;
schema = await resolveJsonSchemaRef(importObject);
break;
}
if (changeSchema) {
Expand Down
Loading

0 comments on commit 7692287

Please sign in to comment.