Skip to content

nxsf/dson-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

  • The string type corresponds to a DSON string.

  • The object type corresponds to a DSON object.

  • The array<T> type corresponds to a DSON array, e.g. array<string> or array<object>.

1.1.2. Additional scalar types

Due to the lack of scalar types in DSON other than strings, the following types are defined:

  • num represents a numeric value. A value of this type must be an optionally signed integer or a floating-point number, e.g. 42 or -17.5.

  • bool represents a boolean value. A value of this type must be a string with either true or false value.

1.1.3. Special types

Special types are defined:

  • The variant<T> type defines a list of possible types delimited by comma, e.g. variant<object, string, my_type>.

  • The enum<V> type defines a list of possible exact scalar values, e.g. enum<42, foo>.

  • The field type represents a DSON object property.

  • The type type represents a user-defined type.

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:

  • Required name property of type string.

  • Required type property of type string representing a type from the type system.

  • Optional desc property of type string.

  • Optional required property of type bool with a default value of false.

  • Optional default property of the same type as the type property.

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:

  • A required name property of type string.

  • An optional desc property of type string.

  • A required fields property of type array<field>.

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 type string.

  • Optional desc property of type string.

  • Required ver property of type string, representing current version of the schema.

    Tip
    Schema definition authors are encouraged to use Semantic Versioning for their schemas.
  • Optional types property of type array<type>.

  • Required fields property of type array<field>.

Appendix A: Standard defining itself

The standard can be partially defined using itself:

link:spec.dson[role=include]

Releases

No releases published

Packages

No packages published