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 Editor 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 student class which extends from the human class.
{
  "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 reference

A student class which reference a faculty class.
{
  "definitions": {
    "Student": {
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        },
        "faculty": {
          "$ref": "Faculty"
        }
      }
    },
    "Faculty": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  },
  "$ref": "Student"
}

Map with string values

A student class which contains a map with arbitrary string properties.
{
  "definitions": {
    "Student": {
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        },
        "properties": {
          "$ref": "Student_Properties"
        }
      }
    },
    "Student_Properties": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    }
  },
  "$ref": "Student"
}

Inline map with string values

A student class which contains an inline map with arbitrary string properties.
{
  "definitions": {
    "Student": {
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        },
        "properties": {
          "type": "object",
          "additionalProperties": {
            "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"
}

Edit this page