mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
event/cmdschema: add JSON schemas for test data
This commit is contained in:
parent
e034c16753
commit
4c0b511c01
7 changed files with 332 additions and 0 deletions
281
event/cmdschema/testdata/commands.schema.json
vendored
Normal file
281
event/cmdschema/testdata/commands.schema.json
vendored
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema#",
|
||||
"$id": "commands.schema.json",
|
||||
"title": "ParseInput test cases",
|
||||
"description": "JSON schema for test case files containing command specifications and test cases",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"spec",
|
||||
"tests"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"spec": {
|
||||
"title": "MSC4391 Command Description",
|
||||
"description": "JSON schema defining the structure of a bot command event content",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"command"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"command": {
|
||||
"type": "string",
|
||||
"description": "The command name that triggers this bot command"
|
||||
},
|
||||
"aliases": {
|
||||
"type": "array",
|
||||
"description": "Alternative names/aliases for this command",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"parameters": {
|
||||
"type": "array",
|
||||
"description": "List of parameters accepted by this command",
|
||||
"items": {
|
||||
"$ref": "#/$defs/Parameter"
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"$ref": "#/$defs/ExtensibleTextContainer",
|
||||
"description": "Human-readable description of the command"
|
||||
},
|
||||
"fi.mau.tail_parameter": {
|
||||
"type": "string",
|
||||
"description": "The key of the parameter that accepts remaining arguments as tail text"
|
||||
},
|
||||
"source": {
|
||||
"type": "string",
|
||||
"description": "The user ID of the bot that responds to this command"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tests": {
|
||||
"type": "array",
|
||||
"description": "Array of test cases for the command",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"description": "A single test case for command parsing",
|
||||
"required": [
|
||||
"name",
|
||||
"input"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The name of the test case"
|
||||
},
|
||||
"input": {
|
||||
"type": "string",
|
||||
"description": "The command input string to parse"
|
||||
},
|
||||
"output": {
|
||||
"description": "The expected parsed parameter values, or null if the parsing is expected to fail",
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"error": {
|
||||
"type": "boolean",
|
||||
"description": "Whether parsing should result in an error. May still produce output.",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"$defs": {
|
||||
"ExtensibleTextContainer": {
|
||||
"type": "object",
|
||||
"description": "Container for text that can have multiple representations",
|
||||
"required": [
|
||||
"m.text"
|
||||
],
|
||||
"properties": {
|
||||
"m.text": {
|
||||
"type": "array",
|
||||
"description": "Array of text representations in different formats",
|
||||
"items": {
|
||||
"$ref": "#/$defs/ExtensibleText"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ExtensibleText": {
|
||||
"type": "object",
|
||||
"description": "A text representation with a specific MIME type",
|
||||
"required": [
|
||||
"body"
|
||||
],
|
||||
"properties": {
|
||||
"body": {
|
||||
"type": "string",
|
||||
"description": "The text content"
|
||||
},
|
||||
"mimetype": {
|
||||
"type": "string",
|
||||
"description": "The MIME type of the text (e.g., text/plain, text/html)",
|
||||
"default": "text/plain",
|
||||
"examples": [
|
||||
"text/plain",
|
||||
"text/html"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"Parameter": {
|
||||
"type": "object",
|
||||
"description": "A parameter definition for a command",
|
||||
"required": [
|
||||
"key",
|
||||
"schema"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"key": {
|
||||
"type": "string",
|
||||
"description": "The identifier for this parameter"
|
||||
},
|
||||
"schema": {
|
||||
"$ref": "#/$defs/ParameterSchema",
|
||||
"description": "The schema defining the type and structure of this parameter"
|
||||
},
|
||||
"optional": {
|
||||
"type": "boolean",
|
||||
"description": "Whether this parameter is optional",
|
||||
"default": false
|
||||
},
|
||||
"description": {
|
||||
"$ref": "#/$defs/ExtensibleTextContainer",
|
||||
"description": "Human-readable description of this parameter"
|
||||
},
|
||||
"fi.mau.default_value": {
|
||||
"description": "Default value for this parameter if not provided"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ParameterSchema": {
|
||||
"type": "object",
|
||||
"description": "Schema definition for a parameter value",
|
||||
"required": [
|
||||
"schema_type"
|
||||
],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"schema_type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"primitive",
|
||||
"array",
|
||||
"union",
|
||||
"literal"
|
||||
],
|
||||
"description": "The type of schema"
|
||||
}
|
||||
},
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"schema_type": {
|
||||
"const": "primitive"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"required": [
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"string",
|
||||
"integer",
|
||||
"boolean",
|
||||
"server_name",
|
||||
"user_id",
|
||||
"room_id",
|
||||
"room_alias",
|
||||
"event_id"
|
||||
],
|
||||
"description": "The primitive type (only for schema_type: primitive)"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"schema_type": {
|
||||
"const": "array"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"required": [
|
||||
"items"
|
||||
],
|
||||
"properties": {
|
||||
"items": {
|
||||
"$ref": "#/$defs/ParameterSchema",
|
||||
"description": "The schema for array items (only for schema_type: array)"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"schema_type": {
|
||||
"const": "union"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"required": [
|
||||
"variants"
|
||||
],
|
||||
"properties": {
|
||||
"variants": {
|
||||
"type": "array",
|
||||
"description": "The possible variants (only for schema_type: union)",
|
||||
"items": {
|
||||
"$ref": "#/$defs/ParameterSchema"
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"schema_type": {
|
||||
"const": "literal"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"required": [
|
||||
"value"
|
||||
],
|
||||
"properties": {
|
||||
"value": {
|
||||
"description": "The literal value (only for schema_type: literal)"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
1
event/cmdschema/testdata/commands/flags.json
vendored
1
event/cmdschema/testdata/commands/flags.json
vendored
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"$schema": "../commands.schema.json#",
|
||||
"spec": {
|
||||
"command": "flag",
|
||||
"source": "@testbot",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"$schema": "../commands.schema.json#",
|
||||
"spec": {
|
||||
"command": "test room reference",
|
||||
"source": "@testbot",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"$schema": "../commands.schema.json#",
|
||||
"spec": {
|
||||
"command": "test room reference",
|
||||
"source": "@testbot",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"$schema": "../commands.schema.json#",
|
||||
"spec": {
|
||||
"command": "test simple",
|
||||
"source": "@testbot",
|
||||
|
|
|
|||
1
event/cmdschema/testdata/commands/tail.json
vendored
1
event/cmdschema/testdata/commands/tail.json
vendored
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"$schema": "../commands.schema.json#",
|
||||
"spec": {
|
||||
"command": "tail",
|
||||
"source": "@testbot",
|
||||
|
|
|
|||
46
event/cmdschema/testdata/parse_quote.schema.json
vendored
Normal file
46
event/cmdschema/testdata/parse_quote.schema.json
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema#",
|
||||
"$id": "parse_quote.schema.json",
|
||||
"title": "parseQuote test cases",
|
||||
"description": "Test cases for the parseQuoted function",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name",
|
||||
"input",
|
||||
"output"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "Name of the test case"
|
||||
},
|
||||
"input": {
|
||||
"type": "string",
|
||||
"description": "Input string to be parsed"
|
||||
},
|
||||
"output": {
|
||||
"type": "array",
|
||||
"description": "Expected output of parsing: [first word, remaining text, was quoted]",
|
||||
"minItems": 3,
|
||||
"maxItems": 3,
|
||||
"prefixItems": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "First parsed word"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Remaining text after the first word"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"description": "Whether the first word was quoted"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue