The following standard defines how to describe complex DSON object schema specifications in DSON.
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.
- schema object
-
The DSON object containing a schema definition.
- described object
-
A DSON object the schema is defined for.
The standard defines a type system which allows to restrict a described object's properties to certain types.
There is a number of built-in types natural to DSON:
Due to the lack of scalar types in DSON other than strings, the following types are defined:
Special types are defined:
The field
object type defines an object describing a DSON object property.
An object of type field
may contain the following properties itself:
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:
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.