From 7b84d6d251233d0cfbc2ee36efbc6d1b961af474 Mon Sep 17 00:00:00 2001 From: Miss Adorable Date: Thu, 29 Feb 2024 05:38:39 +0300 Subject: [PATCH] Enhance json schema (#353) * feat: provide intellisence for configs * feat: more constrains and hints Provide: - examples - better descriptions - url to repo Disallow: - space only strings * fix: add missing titles * fix: help keys Use 'Not provided' placeholder * Revert "fix: help keys" This reverts commit 2a939cf8aeb7d105fe989328034b367ddb93bf25. * fix: don't use strict JSON schema validation * Revert "fix: don't use strict JSON schema validation" This reverts commit 61d50085fb09bf00601b036fa433dc279d53668b. * fix: specify `type` for definition --- .vscode/settings.json | 10 ++++ json-schema/program.json | 100 ++++++++++++++++++++++++--------------- 2 files changed, 71 insertions(+), 39 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..d088d566 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "json.schemas": [ + { + "fileMatch": [ + "programs/*.json" + ], + "url": "./json-schema/program.json" + } + ] +} diff --git a/json-schema/program.json b/json-schema/program.json index 1fcf2d79..2dc75f31 100644 --- a/json-schema/program.json +++ b/json-schema/program.json @@ -1,44 +1,66 @@ { - "title": "Program", - "description": "Specification of files or folders in the $HOME folder for a program", - "type": "object", - "properties": { - "name": { + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "empty": { + "type": "string", + "pattern": "^\\s+$" + } + }, + "title": "specification", + "description": "A specification of files or folders in the $HOME folder for a program\nhttps://github.com/b3nj5m1n/xdg-ninja", + "type": "object", + "required": ["name", "files"], + "properties": { + "name": { + "title": "name", + "description": "A program name\nRestrictions:\n- can't contain just spaces\nhttps://github.com/b3nj5m1n/xdg-ninja", + "type": "string", + "minLength": 1, + "not": { + "$ref": "#/definitions/empty" + }, + "examples": ["abook"] + }, + "files": { + "title": "files", + "description": "Files and folders for a program\nhttps://github.com/b3nj5m1n/xdg-ninja", + "type": "array", + "uniqueItems": true, + "minItems": 1, + "items": { + "description": "A file or a folder for a program\nhttps://github.com/b3nj5m1n/xdg-ninja", + "type": "object", + "required": ["path", "movable", "help"], + "properties": { + "path": { + "title": "path", + "description": "A path to a file or a folder\nRestrictions:\n- can't contain just spaces\nhttps://github.com/b3nj5m1n/xdg-ninja", + "type": "string", + "minLength": 1, + "not": { + "$ref": "#/definitions/empty" + }, + "examples": ["$HOME/.abook"] + }, + "movable": { + "title": "movable", + "description": "Whether a file or a folder is movable to a place other than $HOME\nhttps://github.com/b3nj5m1n/xdg-ninja", + "type": "boolean" + }, + "help": { + "title": "help", + "description": "A help message for a user in markdown\nRestrictions:\n- can't contain just spaces\nhttps://github.com/b3nj5m1n/xdg-ninja", "type": "string", - "description": "Name of the program", - "minLength": 1 - }, - "files": { - "description": "List of files (or folders) associated with the program", - "type": "array", - "items": { - "type": "object", - "properties": { - "path": { - "type": "string", - "description": "Path to file (or folder).", - "minLength": 1 - }, - "movable": { - "type": "boolean", - "description": "Is file (or folder) movable to a place other than $HOME." - }, - "help": { - "type": "string", - "description": "Help text for user. Supports markdown." - } - }, - "required": [ - "path", - "movable", - "help" - ] + "minLength": 1, + "not": { + "$ref": "#/definitions/empty" }, - "minItems": 1 + "examples": [ + "Alias abook to use custom locations for configuration and data:\n\n```bash\nalias abook=abook --config \"$XDG_CONFIG_HOME\"/abook/abookrc --datafile \"$XDG_DATA_HOME\"/abook/addressbook\n```\n" + ] + } } - }, - "required": [ - "name", - "files" - ] + } + } + } }