Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TarantoolBot opened this issue Nov 26, 2024 · 0 comments
Open

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

TarantoolBot opened this issue Nov 26, 2024 · 0 comments
Labels
3.3 config reference [location] Tarantool manual, Reference part

Comments

@TarantoolBot
Copy link
Collaborator

TarantoolBot commented Nov 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.3 config reference [location] Tarantool manual, Reference part
Projects
None yet
Development

No branches or pull requests

2 participants