Schemas are everywhere
Broadly speaking, schemas describe how data is organized in data structures.
Relational schemas
Relational schemas describe how data is organized in relational databases. These schemas are often captured as DDL (data definition language) statements.
Here is an example of a relational schema expressed using DDL commands:
CREATE TABLE books ( book_id INT NOT NULL PRIMARY KEY, title VARCHAR(100), author VARCHAR(100), );
GraphQL schemas
GraphQL schemas describe the shape of the data provided by GraphQL service.
Here is an example of a GraphQL schema:
type Book {
title: String!
author: String!
}JSON schemas
JSON schemas describe the shapes of JSON documents. This then enables the annotation and validation of JSON documents.
Below is an example of a JSON schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/book.schema.json",
"title": "Book",
"description": "A book from the product catalog",
"type": "object",
"properties": {
"title": {
"description": "The title of the book",
"type": "string"
},
"author": {
"description": "The author of the book",
"type": "string"
}
},
"required": [
"title",
"author"
]
}XML schemas
Similar to JSON schemas, XML schemas describe the shapes of XML documents.
Below is an example of an XML schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>OpenAPI
OpenAPI documents describe entire APIs and utilise JSON Schema to describe the data structures.
Apache Avro
Below is an example of an Avro schema:
{
"namespace": "example.avro",
"type": "record",
"name": "Book",
"fields": [
{"name": "title", "type": "string"},
{"name": "author", "type": "string"}
]
}Protocol buffers
Below is an example of a protocol buffers message:
message Book {
string title = 1;
string author = 2;
}