Methods
addProperty
Description
Add a property schema.
Signature
interface addProperty {
(key: string | number, schema: ISchema): Schema // returns the updated Schema instance
}removeProperty
Description
Remove a property schema.
Signature
interface removeProperty {
(key: string | number): Schema // returns the removed Schema instance
}setProperties
Description
Replace all property schemas.
Signature
interface setProperties {
(properties: SchemaProperties): Schema // returns the current Schema instance
}For SchemaProperties, see SchemaProperties.
addPatternProperty
Description
Add a pattern property schema.
Signature
interface addPatternProperty {
(regexp: string, schema: ISchema): Schema // returns the updated Schema instance
}removePatternProperty
Description
Remove a pattern property schema.
Signature
interface removePatternProperty {
(regexp: string): Schema // returns the updated Schema instance
}setPatternProperties
Description
Replace all pattern property schemas.
Signature
interface setPatternProperties {
(properties: SchemaProperties): Schema // returns the current Schema instance
}For SchemaProperties, see SchemaProperties.
setAdditionalProperties
Description
Replace the additionalProperties schema.
Signature
interface setAdditionalProperties {
(properties: ISchema): Schema // returns the additionalProperties Schema instance
}setItems
Description
Replace array item definitions.
Signature
interface setItems {
(items: SchemaItems): SchemaItems // returns the updated SchemaItems object
}For SchemaItems, see SchemaItems.
setAdditionalItems
Description
Replace additional array item definitions.
Signature
interface setAdditionalItems {
(items: ISchema): Schema // returns the updated Schema instance
}For SchemaItems, see SchemaItems.
mapProperties
Description
Map over the current Schema properties in x-index order.
Signature
interface mapProperties<T> {
(mapper: (property: Schema, key: string | number) => T): T[]
}mapPatternProperties
Description
Map over the current Schema patternProperties in x-index order.
Signature
interface mapPatternProperties<T> {
(mapper: (property: Schema, key: string | number) => T): T[]
}reduceProperties
Description
Reduce the current Schema properties in x-index order.
Signature
interface reduceProperties<T> {
(
reducer: (value: T, property: Schema, key: string | number) => T,
initialValue?: T
): T
}reducePatternProperties
Description
Reduce the current Schema patternProperties in x-index order.
Signature
interface reducePatternProperties<T> {
(
reducer: (value: T, property: Schema, key: string | number) => T,
initialValue?: T
): T
}compile
Description
Recursively walks the current Schema object, compiles expression fragments, and returns the Schema instance. You can pass a scope object and consume its variables inside expressions.
Expression fragments are strings that start with {{ and end with }}.
Signature
interface compile {
(scope: any): Schema
}Example
The following example compiles expressions inside a Schema into final values. It is useful when you manually create a Schema instance and want to inject runtime variables before consuming it elsewhere.
import { Schema } from '@formily/json-schema'
const schema = new Schema({
type: 'object',
properties: {
age: {
'type': 'string',
'title': '{{user.name}}\'s age',
'x-visible': '{{showAge}}',
'x-component-props': {
placeholder: '{{user.name}}, please enter your age',
},
},
},
})
schema.compile({
user: { name: 'Alice' },
showAge: true,
})
console.log(schema.properties.age.title)
// Alice's age
console.log(schema.properties.age['x-visible'])
// true
console.log(schema.properties.age['x-component-props'].placeholder)
// Alice, please enter your agefromJSON
Description
Convert plain JSON data into a Schema instance.
Signature
interface fromJSON {
(json: ISchema): Schema
}toJSON
Description
Convert the current Schema instance into plain JSON data.
Signature
interface toJSON {
(): ISchema
}toFieldProps
Description
Convert the current Schema into Formily field model props. See Properties for the field mapping reference.
Signature
import { IFieldFactoryProps } from '@formily/core'
interface toFieldProps {
(): IFieldFactoryProps
}For IFieldFactoryProps, see IFieldFactoryProps.