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.
{
  "title": "Student",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "age": {
      "type": "integer"
    }
  }
}

Model with references

A model mode which contains different references.
{
  "definitions": {
    "Location": {
      "type": "object",
      "properties": {
        "latitude": {
          "type": "number"
        },
        "longitude": {
          "type": "number"
        }
      }
    }
  },
  "title": "Student",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "age": {
      "type": "integer"
    },
    "origin": {
      "$ref": "Location"
    },
    "visited": {
      "type": "array",
      "items": {
        "$ref": "Location"
      }
    }
  }
}

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"
        }
      }
    }
  },
  "title": "ResultSet",
  "type": "object",
  "properties": {
    "entries": {
      "type": "array",
      "items": {
        "$ref": "Student"
      }
    }
  }
}

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"
          }
        }
      }
    }
  },
  "title": "Faculty",
  "type": "object",
  "properties": {
    "description": {
      "type": "string"
    },
    "students": {
      "type": "array",
      "items": {
        "$ref": "StudentMap"
      }
    }
  }
}

Import other TypeSchema specification

Shows how to import and use another TypeSchema.
{
  "$import": {
    "my_ns": "https://raw.githubusercontent.com/apioo/typeschema/master/www/src/Website/resource/examples/generic.json"
  },
  "title": "Faculty",
  "type": "object",
  "properties": {
    "description": {
      "type": "string"
    },
    "students": {
      "type": "array",
      "items": {
        "$ref": "my_ns:StudentMap"
      }
    }
  }
}