Schema
| Type | Required | Default |
|---|---|---|
| Schema | Yes | undefined |
Schema will be an object that describes the details of our field.
const config = {
key: ...,
fields: {
firstName: {
schema: {
type: "string",
is_optional: true,
is_array: false,
object_schema: null,
enum: null,
default_value: null
},
},
},
};type
| Type | Required | Default |
|---|---|---|
| string | Yes | undefined |
The type of this field. Can be one of these values: string, number, boolean, or object.
is_optional
| Type | Required | Default |
|---|---|---|
| boolean | No | false |
Whether this is a required field or not.
is_array
| Type | Required | Default |
|---|---|---|
| boolean | No | false |
Whether this field is going to be an array of the defined type. For example, if is_array = true and type = string, this field would denote contain an array of strings.
object_schema
| Type | Required | Default |
|---|---|---|
| object | if type="object" | undefined |
If type = object, this field will be required to denote the shape of the object. The value expects another Schema shape.
const config = {
fields: {
author: {
schema: {
type: "object",
object_schema: {
// Nested schema object
fields: {
firstName: {
schema: {
type: "string"
}
},
lastName: {
schema: {
type: "string"
}
}
}
}
}
}
}
};enum
| Type | Required | Default |
|---|---|---|
| string[] or number[] | No | undefined |
If you want to limit the values to a certain selection, specify an enum.
const config = {
fields: {
genres: {
schema: {
type: "string",
enum: ["Action", "Comedy", "Thriller", "Drama"]
}
}
}
};dynamic_enum
| Type | Required | Default |
|---|---|---|
| Request | No | undefined |
Dynamic enum allows you to use the data from a request to populate the values within a dropdown element. The data returned from the request should be an array of data. If your data is within a response object. you can use the data_path property to target where your array of data lives within the response object.
With a configuration like the one below, Interweave will render a dropdown select with the
const config = {
fields: {
genres: {
schema: {
type: "string",
dynamic_enum: {
uri: "https://example.com/genres",
http_method: "GET",
data_path: "data.response",
error_path: "data.error.message",
headers: {
"Content-Type": "application/json"
}
}
}
}
}
};default_value
| Type | Required | Default |
|---|---|---|
| any | No | undefined |
Default value for this field. If no value is provided, this value will be used. This value should adhere to the other rules specified in the field's schema.