Skip to content

The library ignores conditional schema structure #132

@andreyqin

Description

@andreyqin

Hi! Thanks for this library guys! I'm implementing a JSON editor and I want the user to get autocomplete in one field depending on the value of another field. For this purpose I've got the schema similar to below:

const schema = {
    type: 'object',
    properties: {
        type: {
            type: 'string',
            enum: ['Test_1', 'Test_2'],
        },
        props: {
            type: 'object',
        },
    },
    allOf: [
        {
            if: {
                properties: {
                    type: { const: 'Test_1' },
                },
            },
            then: {
                properties: {
                    props: {
                        properties: {
                            test1Props: { type: 'string' },
                        },
                        additionalProperties: false,
                    },
                },
            },
        },
        {
            if: {
                properties: {
                    type: { const: 'Test_2' },
                },
            },
            then: {
                properties: {
                    props: {
                        properties: {
                            test2Props: { type: 'number' },
                        },
                        additionalProperties: false,
                    },
                },
            },
        },
    ],
};

So I expect that when I'm typing in "Test_1" in type field, I get only test1Props as a suggestion in props field but instead I get both:

Screenshot 2024-06-18 at 10 58 21

Here is my React component:

<CodeMirror
            extensions={[
            json(),
            linter(jsonParseLinter()),
            linter(jsonSchemaLinter(), {
                needsRefresh: handleRefresh,
            }),
            jsonLanguage.data.of({
                autocomplete: jsonCompletion(),
            }),
            hoverTooltip(
                jsonSchemaHover({
                    getHoverTexts: getHoverText,
                    formatHover: createHoverTooltip,
                }),
                { hoverTime: 0 },
            ),
            stateExtensions(schema),
]}
            value={value}
            theme='dark'
            height='100%'
            className={cn(styles.root, className)}
            onChange={handleChange}
        />

I'm using: node v18.7.0, "codemirror-json-schema": "^0.7.8", "@codemirror/lang-json": "^6.0.1", "@uiw/react-codemirror": "^4.22.1".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions