Developer

This chapter provides some guidelines for developers how to build a TypeSchema code generator.


Overview

The following TypeSchema shows most keywords with a concrete reference to the specification, which should give you a first overview of the available keywords.

{
  "$import": {
    "my_ns": "file:///generic.json"
  },
  "definitions": {
    "Human": {
      "type": "struct",
      "properties": {
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        }
      }
    },
    "Student": {
      "parent": "Human",
      "type": "struct",
      "properties": {
        "matricleNumber": {
          "type": "integer"
        }
      }
    },
    "StudentMap": {
      "$ref": "Map",
      "$template": {
        "T": "Student"
      }
    },
    "Map": {
      "type": "struct",
      "properties": {
        "totalResults": {
          "type": "integer"
        },
        "entries": {
          "type": "array",
          "items": {
            "$generic": "T"
          }
        }
      }
    }
  },
  "$ref": "StudentMap"
}

Parse type

The following algorithm shows how to create an object in-memory representation of a type. It assumes that you pass the raw JSON decoded object into this function and it returns a concrete type.

function parseType(object json): Type


Type detection

The following algorithm shows how to detect the correct type from a decoded JSON value.

function newType(object json): Type|null


Reference resolution

The following algorithm shows how to resolve a reference.

function resolveReference(ReferenceType type, Definitions definitions): Type

Edit this page