The BAQ Schema format was inspired by JSON Schema and JSON Type Definition. It should look familiar to anyone with experience with either. This new format was introduced to meet the following design goals:
SchemaA BAQ Schema is a union of all the possible schema types. The type is the union discriminator. These properties are common to all schemas:
type enum
Type of schema this object represents.
Values: "object", "array", "boolean", "string", "int", "number", "null", "tag_link", "blob_link", "entity_link", "record_link", "version_link", "map", "union", "intersection", "ref", "never"
definitions {[string]: Schema} optional
Named schemas that can be used by any child RefSchema.
This is useful to avoid duplication and to define recursive schemas.
ObjectSchemaSchema for a JSON object with known properties.
{
"type": "object",
"properties": {
"hello": {
"type": "string"
},
"world": {
"type": "string",
"optional": true
}
}
}
type enum
"object"properties {[string]: Schema}
Properties of the represented object, and their corresponding schemas.
Each property value is a Schema with this additional property:
optional boolean optional
Allow the property to be omitted.
Default: false
ArraySchemaSchema for a JSON array.
{
"type": "array",
"items": {
"type": "string"
}
}
type enum
"array"items Schema
min_items int optional
max_items int optional
distinct_items boolean optional
Require all items in the array to have distinct values.
Default: false
BooleanSchemaSchema for a JSON boolean value.
{
"type": "boolean"
}
type enum
"boolean"enum boolean[] optional
StringSchemaSchema for a JSON string value.
{
"type": "string"
}
type enum
"string"enum string[] optional
min_length int optional
max_length int optional
All strings must be normalized in Unicode Normalization Form C (NFC).
All lengths are in Unicode code points.
IntSchemaSchema for a JSON integer number.
{
"type": "int"
}
type enum
"int"enum int[] optional
min int optional
max int optional
NumberSchemaSchema for a JSON floating-point number.
{
"type": "number"
}
type enum
"number"enum number[] optional
min number optional
max number optional
NullSchemaSchema for a JSON null value.
{
"type": "null"
}
type enum
"null"TagLinkSchemaSchema for a BAQ Tag Link.
{
"type": "tag_link"
}
type enum
"tag_link"enum string[] optional
min_length int optional
max_length int optional
sort_property boolean optional
Allow sorting of records on this property.
Default: false
BlobLinkSchemaSchema for a BAQ Blob Link.
{
"type": "blob_link"
}
type enum
"blob_link"max_size int optional
content_types string[] optional
content_type of the linked blob.EntityLinkSchemaSchema for a BAQ Entity Link.
{
"type": "entity_link"
}
type enum
"entity_link"RecordLinkSchemaSchema for a BAQ Record Link.
{
"type": "record_link"
}
type enum
"record_link"record_types RecordLink[] optional
existential boolean optional
Make the record’s existence depend on the linked record.
Default: false
VersionLinkSchemaSchema for a BAQ Version Link.
{
"type": "version_link"
}
type enum
"version_link"record_types RecordLink[] optional
MapSchemaSchema for a JSON object with generic properties.
{
"type": "map",
"values": {
"type": "string"
}
}
type enum
"map"values Schema
UnionSchemaUnion of multiple schemas. Valid if at least one of the sub-schemas is valid.
{
"type": "union",
"schemas": [{"type": "string"}, {"type": "int"}]
}
type enum
"union"schemas Schema[]
Schemas in the union.
It must contain a minimum of two schemas.
IntersectionSchemaIntersection of multiple schemas. Valid if all sub-schemas are valid.
{
"type": "intersection",
"schemas": [
{
"type": "object",
"properties": {"hello": {"type": "string"}}
},
{
"type": "object",
"properties": {"world": {"type": "string"}}
}
]
}
type enum
"intersection"schemas Schema[]
Schemas in the intersection.
It must contain a minimum of two schemas.
RefSchemaRe-use a schema defined in a definitions property somewhere upstream.
{
"definitions": {
"name": {"type": "string"}
},
"type": "ref",
"ref": "name"
}
type enum
"ref"ref string
Name of the schema to use.
In case of duplicate naming, the schema closest to the ref is used.
Refs can be recursive.
NeverSchemaSchema that always fails validation.
{
"type": "never"
}
type enum
"never"Define a schema for a user profile object:
{
"type": "object",
"properties": {
"name": {
"type": "string",
"min_length": 1,
"max_length": 100
},
"birth_year": {
"type": "int",
"min": 1900
},
"favorite_color": {
"type": "string",
"enum": ["red", "green", "blue"]
}
}
}
Valid JSON:
{
"name": "Tony Stark",
"birth_year": 1970,
"favorite_color": "red"
}
To avoid repeating the same schema again and again, use definitions and ref schemas. A ref schema can point to any upstream definition.
{
"definitions": {
"name": {
"type": "string",
"min_length": 1,
"max_length": 100
}
},
"type": "object",
"properties": {
"mother_name": {
"type": "ref",
"ref": "name"
},
"father_name": {
"type": "ref",
"ref": "name"
},
"sibling_names": {
"type": "array",
"items": {"type": "ref", "ref": "name"}
}
}
}
Valid JSON:
{
"mother_name": "Maria",
"father_name": "Howard",
"sibling_names": ["Paul", "Henry"]
}
A ref schema can also be used to define a recursive schema. In this example, a user profile can have friends that are each also represented by a user profile (and can have friends of their own, and so on).
{
"definitions": {
"profile": {
"type": "object",
"properties": {
"name": {
"type": "string",
"min_length": 1,
"max_length": 100
},
"friends": {
"type": "array",
"items": {
"type": "ref",
"ref": "profile"
}
}
}
}
},
"type": "ref",
"ref": "profile"
}
Valid JSON:
{
"name": "Maggie",
"friends": [
{
"name": "Sean",
"friends": []
},
{
"name": "Andersen",
"friends": [
{
"name": "Samantha",
"friends": []
}
]
}
]
}