Specification
Schema

Schema

TypeRequiredDefault
SchemaYesundefined

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

TypeRequiredDefault
stringYesundefined

The type of this field. Can be one of these values: string, number, boolean, or object.

is_optional

TypeRequiredDefault
booleanNofalse

Whether this is a required field or not.

is_array

TypeRequiredDefault
booleanNofalse

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

TypeRequiredDefault
objectif 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

TypeRequiredDefault
string[] or number[]Noundefined

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

TypeRequiredDefault
RequestNoundefined

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

TypeRequiredDefault
anyNoundefined

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.