Skip to content

Commit

Permalink
refactor(schema): remove validation for $schema
Browse files Browse the repository at this point in the history
add version supported tip
  • Loading branch information
Kinplemelon authored and ysfscream committed Mar 12, 2024
1 parent fa154c9 commit 7422c06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/i18n/RuleEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1265,4 +1265,8 @@ It's recommended to use a template syntax, e.g., \`\${'{'}timestamp{'}'}\` or \`
zh: '输入 JSON 以生成 JSON Schema',
en: 'Enter JSON to generate JSON Schema',
},
JSONSchemaVersionTip: {
zh: `当前支持 JSON Schema draft-03、draft-04 和 draft-06 版本。`,
en: `JSON Schema versions draft-03, draft-04, and draft-06 are supported.`,
},
}
13 changes: 12 additions & 1 deletion src/views/RuleEngine/Schema/components/SchemaRegistryForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
</el-col>
<el-col :span="24">
<el-form-item label="Schema" prop="source">
<template #label>
<FormItemLabel
label="Schema"
:desc="selectedJSON ? tl('JSONSchemaVersionTip') : undefined"
desc-marked
popper-class="is-wider"
/>
</template>
<div class="monaco-container">
<Monaco
v-model="schemaForm.source"
Expand Down Expand Up @@ -70,6 +78,7 @@ import useI18nTl from '@/hooks/useI18nTl'
import { SchemaRegistryType } from '@/types/enum'
import { SchemaRegistry } from '@/types/rule'
import ajv from 'ajv'
import draft6MetaSchema from 'ajv/dist/refs/json-schema-draft-06.json'
import {
PropType,
WritableComputedRef,
Expand Down Expand Up @@ -109,7 +118,6 @@ const FormCom = ref()
const { schemaTypeOpts } = useSchemaType()
const ajvInstance = new ajv()
const { createRequiredRule, createCommonIdRule } = useFormRules()
const rules = ref({
name: [...createRequiredRule(t('Base.name')), ...createCommonIdRule()],
Expand All @@ -123,9 +131,12 @@ const rules = ref({
return
}
try {
const ajvInstance = new ajv({ validateSchema: false })
ajvInstance.addMetaSchema(draft6MetaSchema)
ajvInstance.compile(JSON.parse(value))
callback()
} catch (e) {
console.error(e)
callback(new Error(tl('invalidJSONSchema')))
}
},
Expand Down

0 comments on commit 7422c06

Please sign in to comment.