Skip to content

":jsonschema()" method to obtain config's JSON Schema #4659

Open
@TarantoolBot

Description

@TarantoolBot

Dev. issue: tarantool/tarantool#10636

Product: Tarantool
Since: 3.3.0
Root document: https://www.tarantool.io/ru/doc/latest/reference/reference_lua/config/
SME: @ mandesero

Details

Connected with #4658

API Reference:
config:jsonschema() -- Generates the JSON schema of the cluster
configuration as a Lua table.

config API/object config:

config:jsonschema()
JSON schema of the cluster configuration in the form
of a Lua table.

Return:
A Lua table representing the JSON schema of the cluster
configuration.

Example:

local config = require('config')
local json = require('json')
local fio = require('fio')

-- Generate the JSON schema of the cluster configuration as a Lua table
local schema = config:jsonschema()

-- Encode the schema as a JSON string
local schema_json = json.encode(schema)

-- Save the schema to a file named 'config-schema.json'
local file_path = fio.pathjoin(fio.cwd(), 'config-schema.json')
local file = fio.open(file_path, {'O_WRONLY', 'O_CREAT', 'O_TRUNC'}, tonumber('644', 8))

if file then
    file:write(schema_json)
    file:close()
end
  • CLI Validation with check-jsonschema
    Once the config-schema.json file is generated, users can validate their
    configuration files using CLI tools such as check-jsonschema:
check-jsonschema --schemafile=config-schema.json my-config-file.yaml

This ensures that the configuration file is valid according to the schema.

  • IDE Integration
    Users can also import the generated config-schema.json into their IDE to
    enable autocompletion and validation. For instance, in VSCode, using the
    RedHat YAML extension:
  1. Install the RedHat YAML extension.
  2. Configure the extension to use the generated config-schema.json for
    your YAML configuration files by adding the following to your VSCode
    settings.json:
"yaml.schemas": {
    "<path to config-schema.json>": "*.yaml"
}

This will provide autocompletion and validation when editing configuration
files, ensuring they comply with the schema.
Requested by @mandesero in tarantool/tarantool@53d068e.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.3configreference[location] Tarantool manual, Reference part

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions