tarantool / tarantool/doc

`union` schema type in `experimental.config.utils.schema`

Open Beginner friendly
#5,688 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
15
Forks
49
Avg merge
1d 13h
Merged PRs (30d)
3

Description

Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/config/utils_schema/
PR: https://github.com/tarantool/tarantool/pull/12621
Issue: https://github.com/tarantool/tarantool/issues/12539


Summary

The configuration schema module now supports a new schema node type: union.

schema.union() allows describing values that may match one of several schema variants. It is now used instead of legacy mixed scalar types such as string, number and number, string (these types should be dropped from documentation).

Suggested API shape:

schema.union({
    variants = {
        <schema node>,
        <schema node>,
        ...
    },
    discriminator = <function>, -- optional
    <annotations>
})

Where:

  • variants is a non-empty array of schema nodes.
  • discriminator is an optional function that selects one of the variants for a given value.
  • If no discriminator is specified, union works for scalar variants that can be selected by Lua value type.
  • Other schema annotations can be used in the same way as for other schema node types.

Behavior

A value is valid if it matches one of the union variants.

The new type is integrated with:

  • schema validation;
  • get() / set();
  • JSON schema generation;
  • environment variable parsing.

Migration note

The legacy scalar schema types string, number and number, string were removed from experimental.config.utils.schema.

Use schema.union() instead.

Example:

schema.union({
    variants = {
        schema.scalar({type = 'string'}),
        schema.scalar({type = 'number'}),
    },
})

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked configuration schema documentation at reference/reference_lua/config/utils_schema/. Document the experimental.config.utils.schema union node, including variants, optional discriminator, validation behavior, and the migration example; remove references to the legacy string, number and number, string scalar types. Verify the updated page and links in the documentation build.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.