":jsonschema()" method to obtain config's JSON Schema
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 15
- Forks
- 49
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 3
Description
Dev. issue: https://github.com/tarantool/tarantool/issues/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 theconfig-schema.jsonfile is generated, users can validate their
configuration files using CLI tools such ascheck-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 generatedconfig-schema.jsoninto their IDE to
enable autocompletion and validation. For instance, in VSCode, using the
RedHat YAML extension:
- Install the RedHat YAML extension.
- Configure the extension to use the generated
config-schema.jsonfor
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 https://github.com/tarantool/tarantool/commit/53d068ee010a48b407b32aa3971e691c13d9fc1c.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the config API reference at the linked Tarantool documentation root and review the existing config object entries. Document config:jsonschema(), its Lua-table return value, and the provided JSON export, validation, and IDE examples; done means the reference explains the method and examples clearly and the documentation build passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- json, lua
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100