TypeSchema

TypeSchema is a JSON format to describe data models in a language neutral format. A TypeSchema can be easily transformed into specific code for almost any programming language. This helps to reuse core data models in different environments.

Specification Generator

Simple model

A simple model with some scalar properties.
{
  "definitions": {
    "Student": {
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        }
      }
    }
  },
  "$ref": "Student"
}

Model with inheritance

A result set containing a model which extends a different model.
{
  "definitions": {
    "Human": {
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        }
      }
    },
    "Student": {
      "$extends": "Human",
      "type": "object",
      "properties": {
        "studentId": {
          "type": "string"
        }
      }
    }
  },
  "$ref": "Student"
}

Model with discriminator

A model which contains a union type.
{
  "definitions": {
    "Human": {
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        },
        "location": {
          "oneOf": [{
            "$ref": "Web"
          }, {
            "$ref": "World"
          }],
          "discriminator": {
            "propertyName": "type"
          }
        }
      }
    },
    "Location": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        }
      },
      "required": ["type"]
    },
    "Web": {
      "$extends": "Location",
      "type": "object",
      "properties": {
        "url": {
          "type": "string"
        }
      }
    },
    "World": {
      "$extends": "Location",
      "type": "object",
      "properties": {
        "lat": {
          "type": "string"
        },
        "long": {
          "type": "string"
        }
      }
    }
  },
  "$ref": "Human"
}

Advanced model which uses generics

A generic map which uses a specific model.
{
  "definitions": {
    "Student": {
      "type": "object",
      "properties": {
        "matricleNumber": {
          "type": "integer"
        }
      }
    },
    "StudentMap": {
      "$ref": "Map",
      "$template": {
        "T": "Student"
      }
    },
    "Map": {
      "type": "object",
      "properties": {
        "totalResults": {
          "type": "integer"
        },
        "entries": {
          "type": "array",
          "items": {
            "$generic": "T"
          }
        }
      }
    }
  },
  "$ref": "StudentMap"
}

Import other TypeSchema specification

Shows how to import and use another TypeSchema.
{
  "$import": {
    "my_ns": "file:///generic.json"
  },
  "definitions": {
    "Faculty": {
      "type": "object",
      "properties": {
        "description": {
          "type": "string"
        },
        "students": {
          "type": "array",
          "items": {
            "$ref": "my_ns:StudentMap"
          }
        }
      }
    }
  },
  "$ref": "Faculty"
}