Quick Start
@silver-formily/json-schema is the protocol layer behind Silver Formily's JSON Schema development mode. This documentation describes three ways to build forms: Markup Schema, JSON Schema, and JSX Components. Both Markup Schema and JSON Schema rely on the capabilities provided by @silver-formily/json-schema. @silver-formily/json-schema uses a plain object to describe form structure, component mapping, and linkage logic, which makes recursive rendering possible.
In simple terms, different packages are responsible for different parts:
@silver-formily/coremanages the form instance, field state, validation, and effects@silver-formily/json-schemadefines the schema protocol, expression compilation, andSchemaclass APIs- front-end binding libraries such as
@silver-formily/vue, recursively render the schema into a component tree
About This Site
This documentation site focuses on the Silver Formily implementation of the JSON Schema protocol, with runnable examples and a structure that is easier to browse.
Installation
pnpm add @silver-formily/vue @silver-formily/core @silver-formily/json-schema @silver-formily/reactive @silver-formily/reactive-vue @silver-formily/shared@silver-formily/json-schema does not render UI by itself. To turn a schema into an actual Vue form, you still need @silver-formily/core and @silver-formily/vue or another front-end binding library.
Minimal Example
A minimal setup usually has 4 steps:
- Create a form instance with
createForm() - Register the components used in the schema with
createSchemaField() - Declare a
schemawithtype,properties, andx-component - Render everything with
FormProviderandSchemaField
<script setup lang="ts">
import { createForm } from '@silver-formily/core'
import { createSchemaField, FormConsumer, FormProvider } from '@silver-formily/vue'
import { InputBox, TextAreaBox } from './shared'
const { SchemaField } = createSchemaField({
components: {
InputBox,
TextAreaBox,
},
})
const schema = {
type: 'object',
properties: {
nickname: {
'type': 'string',
'title': 'Nickname',
'required': true,
'x-component': 'InputBox',
'x-component-props': {
placeholder: 'For example: Silver',
},
},
bio: {
'type': 'string',
'title': 'Bio',
'x-component': 'TextAreaBox',
'x-component-props': {
rows: 4,
placeholder: 'Write a short introduction',
},
},
},
}
const form = createForm({
values: {
nickname: 'Silver',
bio: 'Hello Silver',
},
})
</script>
<template>
<FormProvider :form="form">
<SchemaField :schema="schema" />
<FormConsumer>
<template #default="{ form: currentForm }">
<pre style="margin-top: 10px; white-space: pre-wrap;">{{ JSON.stringify(currentForm.values, null, 2) }}</pre>
</template>
</FormConsumer>
</FormProvider>
</template>{
"nickname": "Silver",
"bio": "Hello Silver"
}Key points from the example:
createSchemaField({ components })defines which component names are available inx-componentschema.properties.nicknameandschema.properties.biodescribe two fieldsx-component-propsis passed directly to the target componentFormConsumeris only used here to preview current values; in real code you can replace it with submit, validation, or linkage logic