DSON Object Schema Specification Standard
The following standard defines how to describe complex DSON object schema specifications in DSON.
Preface
It is common to have a need to describe an DSON object structure schema: what properties can it have of which types.
The DSON Object Schema Specification Standard standardizes a way to define such a schema using a DSON document.
For example, the following DSON object:
{
name = "John",
age = 18,
hobbies = [{
id = standards,
about = "Loves to write different standards"
}]
}
Matches the following schema:
{
types = [{
name = hobby,
fields = [{
name = id,
type = string,
required = true
}, {
name = about,
type = string,
required = false
}]
}],
fields = [{
name = name,
type = string,
required = true
}, {
name = age,
type = num,
required = false
}, {
name = hobbies,
type = array<hobby>,
required = false
}]
}
The standard follows Semantic Versioning 2.0.
Glossary
- schema object
-
The DSON object containing a schema definition.
- described object
-
A DSON object the schema is defined for.
1. Specification
1.1. Types
The standard defines a type system which allows to restrict a described object's properties to certain types.
1.1.1. Basic DSON types
There is a number of built-in types natural to DSON:
1.1.2. Additional scalar types
Due to the lack of scalar types in DSON other than strings, the following types are defined:
1.1.3. Special types
Special types are defined:
1.1.4. field
type
The field
object type defines an object describing a DSON object property.
An object of type field
may contain the following properties itself:
1.1.5. User-defined types
A Schema object may contain user-defined object type declarations of type type
in its types
property.
User-defined types can be referenced by the value of the name
property of a type
object.
Referencing an undefined type, i.e. the one which is not defined in the schema object’s types
property, is errornous.
An object of type type
may contain the following properties itself:
1.2. Schema object
A DSON document representing a schema must consist of a single DSON object referenced as the schema object.
The schema object may contain the following DSON properties:
-
Optional
name
property of typestring
. -
Optional
desc
property of typestring
. -
Required
ver
property of typestring
, representing current version of the schema.TipSchema definition authors are encouraged to use Semantic Versioning for their schemas.
Appendix A: Standard defining itself
The standard can be partially defined using itself:
{
name = "DSON Object Schema Specification Standard",
desc = "The standard defining itself",
ver = 0.0.0,
types = [{
name = type_def,
desc = "A user-defined type",
fields = [{
name = name,
type = string,
desc = "Name of the type"
required = true
}, {
name = desc,
type = string,
desc = "Description of the type",
required = false
}, {
name = fields,
type = array<field_def>,
desc = "Fields of the type",
required = true
}]
}, {
name = field_def,
desc = "An object field",
fields = [{
name = name,
type = string,
desc = "A field name",
required = true
}, {
name = type,
type = string,
desc = "A field type restriction",
required = true
}, {
name = desc,
type = string,
desc = "A field description",
required = false
}, {
name = required,
type = bool,
desc = "Whether is the field required",
default = false
}, {
name = default,
type = string,
desc = "A default value for the field of matching type",
required = false
}]
}],
fields = [{
name = name,
type = string,
desc = "The schema name"
}, {
name = desc,
type = string,
desc = "The schema description"
}, {
name = ver,
type = string,
desc = "The schema version"
}, {
name = types,
type = array<type_def>,
desc = "Types defined for the schema",
}, {
name = fields,
type = array<field_def>,
desc = "The top-level object fields",
required = true
}]
}