JSON Schema for `viktor.config.toml`

Description of the limitation and why it is relevant to address

As a developer I want to be assisted in editing viktor.config.toml in my code editor, so I’m sheltered from typo or other mistakes.

I think this is relevant for the VIKTOR platform because it prevent “silly” errors, which will only show up once a developer tries to publish an app.

I’m aware it’s a really small and niche “feature”, so perhaps the workaround is fine.

Submitter proposed design

I’m using the Even Better TOML extension in VS Code, that support schema validation through schema json files. Below is an example I made.

By specifying the schema, it can validate the content of the tom file. Here’s a screenshot of a typo I hadn’t noticed before. Apparently I missed the “s” in assets_path

It would be nice if the schema could be uploaded to json-schema.org, so we developers can all use the same schema. In that way you could update the schema once there are new options.

Example schema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Viktor configuration file",
    "description": "The `viktor.config.toml` file is used to set configuration settings for your app, and is placed on the top-level of the application folder.",
    "type": "object",
    "properties": {
        "app_type": {
            "description": "The type of app",
            "type": "string",
            "enum": [
                "editor",
                "simple",
                "tree"
            ]
        },
        "assets_path": {
            "description": "Defines the directory where assets (e.g. images) are stored",
            "type": "string"
        },
        "enable_privileged_api": {
            "description": "With this key, the application code is able to bypass user access restrictions",
            "type": "boolean"
        },
        "python_version": {
            "description": "Specify the Python version to publish the application with",
            "type": "string",
            "enum": [
                "3.8",
                "3.9",
                "3.10",
                "3.11"
            ]
        },
        "welcome_text": {
            "description": "A welcome text can be customized, which will be shown to the user upon entering the application dashboard. The value is a path pointing to a file located relative to viktor.config.toml. The file supports styling with Markdown.",
            "type": "string"
        }
    },
    "required": [
        "app_type"
    ],
    "additionalProperties": false
}

Current workarounds

Manually check the file, or try to publish it. Or use the above schema just locally.

Thanks for your feature request! Can imagine this makes it easier.

Is it also possible to use local schemas? That way developers can already use your schema.

BTW: the create-app command also creates a config with commented out attributes, so using that might already help for those not aware.

Yes, it’s possible to use the schema locally. I saved the schema as viktor-config-toml.schema.json next to the toml file, like

my-folder
├── app.py
├── requirements.txt
└── viktor.config.toml
└── viktor-config-toml.schema.json

And added this first line in the toml file

#:schema viktor-config-toml.schema.json

An example viktor.config.toml file would be:

#:schema viktor-config-toml.schema.json
app_type = 'tree'
python_version = '3.10'
enable_privileged_api = false
welcome_text = "CHANGELOG.md"
assets_path = "assets"

The schema directive was taken from documentation from the library used in the extensions.

But; I haven’t yet tested if viktor-cli publish aceepts that extra line.

1 Like