Skip to content

Add JSON Schema & XML DTD definitions of message data model #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
1. [Registry](registry.md)
1. [`registry.dtd`](registry.dtd)
1. [Formatting](formatting.md)
1. [Interchange data model](data-model/README.md)

## Introduction

Expand Down
8 changes: 6 additions & 2 deletions spec/data-model.md → spec/data-model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ or for other operations to be performed on or with messages in this representati
Implementations are not required to use this data model for their internal representation of messages.

To ensure compatibility across all platforms,
this interchange data model is defined in terms of JSON-compatible values
using TypeScript syntax for their definition.
this interchange data model is defined here using TypeScript notation.
Two equivalent definitions of the data model are also provided:
- [`message.json`](./message.json) is a JSON Schema definition,
for use with message data encoded as JSON or compatible formats, such as YAML.
- [`message.dtd`](./message.dtd) is a document type definition (DTD),
for use with message data encoded as XML.

## Messages

Expand Down
31 changes: 31 additions & 0 deletions spec/data-model/message.dtd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!ELEMENT message (declaration*,(pattern|(selectors,variant+)))>

<!ELEMENT declaration (expression)>
<!ATTLIST declaration name NMTOKEN #REQUIRED>

<!ELEMENT selectors (expression)+>
<!ELEMENT variant (key+,pattern)>
<!ELEMENT key (#PCDATA)>
<!ATTLIST key default (true | false) "false">

<!ELEMENT pattern (#PCDATA | expression)*>
<!ELEMENT expression (literal | variable | function | reserved)>

<!ELEMENT literal (#PCDATA)>
<!ATTLIST literal quoted (true | false) #REQUIRED>

<!ELEMENT variable (EMPTY)>
<!ATTLIST variable name NMTOKEN #REQUIRED>

<!ELEMENT function (operand?,option*)>
<!ATTLIST function
kind (open | close | value) #REQUIRED
name NMTOKEN #REQUIRED
>
<!ELEMENT operand (literal | variable)>
<!ELEMENT option (literal | variable)>
<!ATTLIST option name NMTOKEN #REQUIRED>

<!ELEMENT reserved (operand?,source)>
<!ATTLIST reserved sigil CDATA #REQUIRED>
<!ELEMENT source (#PCDATA)>
162 changes: 162 additions & 0 deletions spec/data-model/message.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model/message.json",

"oneOf": [{ "$ref": "#/$defs/message" }, { "$ref": "#/$defs/select" }],

"$defs": {
"literal": {
"type": "object",
"properties": {
"type": { "const": "literal" },
"quoted": { "type": "boolean" },
"value": { "type": "string" }
},
"required": ["type", "quoted", "value"]
},
"variable": {
"type": "object",
"properties": {
"type": { "const": "variable" },
"name": { "type": "string" }
},
"required": ["type", "name"]
},
"value": {
"oneOf": [{ "$ref": "#/$defs/literal" }, { "$ref": "#/$defs/variable" }]
},

"function": {
"type": "object",
"properties": {
"type": { "const": "function" },
"kind": { "enum": ["open", "close", "value"] },
"name": { "type": "string" },
"operand": { "$ref": "#/$defs/value" },
"options": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"value": { "$ref": "#/$defs/value" }
},
"required": ["name", "value"]
}
}
},
"required": ["type", "kind", "name"]
},
"reserved": {
"type": "object",
"properties": {
"type": { "const": "reserved" },
"sigil": {
"enum": ["!", "@", "#", "%", "^", "&", "*", "<", ">", "?", "~"]
},
"source": { "type": "string" },
"operand": { "$ref": "#/$defs/value" }
},
"required": ["type", "sigil", "source"]
},

"text": {
"type": "object",
"properties": {
"type": { "const": "text" },
"value": { "type": "string" }
},
"required": ["type", "value"]
},
"expression": {
"type": "object",
"properties": {
"type": { "const": "expression" },
"body": {
"oneOf": [
{ "$ref": "#/$defs/literal" },
{ "$ref": "#/$defs/variable" },
{ "$ref": "#/$defs/function" },
{ "$ref": "#/$defs/reserved" }
]
}
},
"required": ["type", "body"]
},
"pattern": {
"type": "object",
"properties": {
"body": {
"type": "array",
"items": {
"oneOf": [
{ "$ref": "#/$defs/text" },
{ "$ref": "#/$defs/expression" }
]
}
}
},
"required": ["body"]
},

"declarations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"value": { "$ref": "#/$defs/expression" }
},
"required": ["target", "value"]
}
},
"variant-key": {
"oneOf": [
{ "$ref": "#/$defs/literal" },
{
"type": "object",
"properties": {
"type": { "const": "*" },
"value": { "type": "string" }
},
"required": ["type"]
}
]
},
"message": {
"type": "object",
"properties": {
"type": { "const": "message" },
"declarations": { "$ref": "#/$defs/declarations" },
"pattern": { "$ref": "#/$defs/pattern" }
},
"required": ["type", "declarations", "pattern"]
},
"select": {
"type": "object",
"properties": {
"type": { "const": "select" },
"declarations": { "$ref": "#/$defs/declarations" },
"selectors": {
"type": "array",
"items": { "$ref": "#/$defs/expression" }
},
"variants": {
"type": "array",
"items": {
"type": "object",
"properties": {
"keys": {
"type": "array",
"items": { "$ref": "#/$defs/variant-key" }
},
"value": { "$ref": "#/$defs/pattern" }
},
"required": ["keys", "value"]
}
}
},
"required": ["type", "declarations", "selectors", "variants"]
}
}
}