Have you thought about adding schema to http://schemastore.org/json/ ?
Hi @antonmarin,
Thanks for the suggestion! I wasn't aware that this existed, but I liked the idea.
I'd need help with it, though, since I don't really know the JSON schema format to write one.
Also, we'd probably probably have some challenges describing a schema for it because:
"echo foo"{cmd: "echo foo", silent: true}{task: echo, vars: {VALUE: foo}})I don't know if allowing different types for an attributes is supported by JSON Schema
Some attributes accepts more than one "type" like either a string or an object with different keys allowed
This is no problem, you would use the "anyOf" clause.
EDIT: I missed the information in the title stating the purpose.
If anyone want to have a shot at this, I started scrabbling down a a schema. It's not complete or necessarily right, but it may serve as a starting point on how you could address multiple versions etc.
I am not going to spend any time completing such a schema (at least not now), but I am happy to do reviews and comment on it.
{
"anyOf": [
{
"title": "Taskfile v1",
"type": "object",
"additionalProperties": {"$ref": "#/definitions/task.v1"}
},
{
"title": "Taskfile v2.0",
"type": "object",
"properties": {
"version": {"type": "string", "enum": ["2", "2.0"]},
"vars": {"$ref": "#/definitions/vars/v1"},
"tasks": {"type": "object", "additionalProperties": {"$ref": "#/definitions/task/v1"}} // no changes
}
},
{
"title": "Taskfile v2.1",
"type": "object",
"properties": {
"version": {"type": "string", "enum": ["2", "2.1"]},
"vars": {"$ref": "#/definitions/vars/v1"},
"tasks": {"type": "object", "additionalProperties": {"$ref": "#/definitions/task/v2.1"}},
"output": {"type": "string", "enum": ["interleaved", "group", "prefixed"], "default": "interleaved"}
}
},
],
"definitions": {
"vars/v1": {"type": "object", "additionalProperties": {"$ref": "#/definitions/var/v1"}},
"var/v1": {...},
"task/v1": {
"type": "object",
"properties": {
"vars": {"$ref": "#/definitions/vars/v1"},
"cmds": {"type": "array", "items": {"$ref":"#/definitions/cmd/v1"}}
}
},
// we don't need to repeat the v1 structure for v2.0 if there where no changes - just create new definition when
// it's actually needed.
"task/v2.1": { // task object is unchanged until 2.1, when "prefixed" was added and "ignore_errors" was allowed.
"type": "object",
"properties": {
"vars": {"$ref": "#/definitions/vars/v1"},
"cmds": {"type": "array", "items": {"$ref":"#/definitions/cmd/v1"}}
}
},
"cmd/v1": {
"anyOf": [
{
"type": "string"
},
{
"type": "object",
"required": ["cmd"],
"properties": {
"cmd":{"type": "string"},
"vars": {"$ref": "#/definitions/vars/v1"}
}
},
{
"type": "object",
"required": ["task"],
"properties": {
"cmd":{"type": "string"},
"vars": {"$ref": "#/definitions/vars/v1"}
}
}
]
},
// we don't need to repeat the v1 structure for v2.0 if there where no changes.
"cmd/v2.1": {...}, // Same as v1, but add "ignore_errors" for example...
}
}
@smyrman Thanks for taking a first try on it!
If anyone know how to test such schema inside a code editor (like VSCode), let me know.
Any updates on this?
@hanabi1224 Sorry, but I don't plan to work on this feature for now. Contribution with this would be really welcome, though!
I have been working on a vscode extension for task to provide Intellisense for users. I created the schema for validating Taskfiles and it;s available here: https://github.com/paulvarache/vscode-taskfile/blob/master/schemas/taskfile.schema.json
This is only for v2.8, but the version can be matched and using anyOf automatically select the correct properties in the schema. I will add support for v3 when it comes out, but don't think I will support older version.
Unfortunately, vscode does not come with yaml validation by default. The extension yaml from RedHat adds support for this. You can use its configuration to enable the schema. The vscode extension vscode-taskfile configures vscode automatically, but is still experimental
Here the schema for version 3.
Most helpful comment
I have been working on a vscode extension for
taskto provide Intellisense for users. I created the schema for validatingTaskfiles and it;s available here: https://github.com/paulvarache/vscode-taskfile/blob/master/schemas/taskfile.schema.jsonThis is only for v2.8, but the version can be matched and using
anyOfautomatically select the correct properties in the schema. I will add support for v3 when it comes out, but don't think I will support older version.Unfortunately, vscode does not come with yaml validation by default. The extension yaml from RedHat adds support for this. You can use its configuration to enable the schema. The vscode extension vscode-taskfile configures vscode automatically, but is still experimental