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

Autocomplete for schema with conditions not working #129

Open
andreyqin opened this issue Jun 10, 2024 · 1 comment
Open

Autocomplete for schema with conditions not working #129

andreyqin opened this issue Jun 10, 2024 · 1 comment

Comments

@andreyqin
Copy link

andreyqin commented Jun 10, 2024

Hi there! First of all, thanks for this library, it really helps me building a JSON editor with a custom json format and conveniently validate it. Unfortunately, I ran into an issue where JSON schema with conditions doesn't trigger autocomplete to show up. For instance, I have a json structure like below:

const schema = {
    type: 'object',
    properties: {
        type: {
            type: 'string',
        },
        props: {
            type: 'number',
        },
    },
    allOf: [
        {
            if: {
                properties: {
                    type: { const: 'Test' },
                },
            },
            then: {
                properties: {
                    props: { type: 'string', enum: ['a', 'b'] },
                },
            },
        },
        {
            if: {
                properties: {
                    type: { const: 'Test2' },
                },
            },
            then: {
                properties: {
                    props: { type: 'string', enum: ['c', 'e'] },
                },
            },
        },
    ],
};

And I expect that when I type in "Test" into "type" field I get "a" and "b" hints for "props" field, but instead I get nothing (it still shows that it's number type, although validation works correctly):

Screenshot 2024-06-10 at 17 12 16

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".

@imolorhe
Copy link
Collaborator

Seems json-schema-library doesn't fully derive nested schema from a pointer based on the data

acao pushed a commit that referenced this issue Sep 6, 2024
As mentioned in #129 we don't get fully resolved schemas based on the
data. Following the discussion in
sagold/json-schema-library#61, that appears to
be expected.

The workaround I implemented is to "fake" a deep schema resolution by
performing the shallow schema resolution on the direct children
properties of the schema (we only really care about the direct children
in this context).
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

No branches or pull requests

2 participants