Skip to content
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

Imported array is flattened in the parent array rather than replacing $import node #478

Closed
tom-tan opened this issue Dec 1, 2021 · 1 comment · Fixed by #480
Closed

Comments

@tom-tan
Copy link
Member

tom-tan commented Dec 1, 2021

The spec says:

Once loaded and processed, the $import node is replaced in the document structure by the object or array yielded from the import operation.

However, when the loaded object is an array, it is flattened in the parent array rather than replacing $import node.

How to reproduce

parent.json:

{
    "form": [
        "bar",
        {
            "$import": "import.json"
        }
    ]
}

import.json

["hello", "world"]
$ schema-salad-tool --print-pre parent.json

Expected behavior

The $import node is replaced by an array as follows:

$ schema-salad-tool --print-pre parent.json
{
    "form": [
        "bar",
        [
            "hello",
            "world"
        ]
    ],
    "name": "file:///workspaces/schema_salad/parent.json"
}

Actual behavior

Elements in the array in the $imported document are flattened in the parent array as follows:

$ schema-salad-tool --print-pre parent.json
{
    "form": [
        "bar",
        "hello",
        "world"
    ],
    "name": "file:///workspaces/schema_salad/parent.json"
}

Versions

$ schema-salad-tool --version
/home/vscode/.local/bin/schema-salad-tool Current version: 8.2.20211116214159

Note that this undocumented behavior is already used in metaschema.

@tetron
Copy link
Member

tetron commented Dec 3, 2021

You are right. This should be documented. Possibly we could introduce a new operation that has explicit insert/merge behavior and make import behave consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants