jsonnext / codemirror-json-schema

A JSONSchema enabled mode for codemirror 6, for json4 and json5, inspired by monaco-json
https://codemirror-json-schema.netlify.app
MIT License
56 stars 9 forks source link

getHoverTexts doesn't receive schema's description for tree structure #130

Open andreyqin opened 3 weeks ago

andreyqin commented 3 weeks ago

Hi! I'm implementing a JSON editor and I want the user to get some hints when hovering on a field inside the editor. The issue is that if I have a tree schema structure like below:

const schema = {
    type: 'object',
    properties: {
        props: {
            type: 'array',
            items: {
                type: 'string',
                enum: ['a', 'b', 'c'],
            },
            description: 'This is props field',
        },
        children: {
            type: 'array',
            items: { $ref: '#' },
            description: 'This is children field',
        },
    },
};

getHoverTexts only receives the schema's description for fields on first level of nesting:

{
  "props": ["a"],
  "children": [
    {
      "props": ["b"]
    }
  ]
}

So when hovering on first props, getHoverTexts's callback receives the following schema:

{
    "type": "array",
    "items": {
        "type": "string",
        "enum": [
            "a",
            "b",
            "c"
        ]
    },
    "description": "This is props field"
}

So I get the description and can show it to the end user. But when I'm hovering on the nesting props, I get:

{
    "type": "array",
    "items": {
        "type": "string"
    }
}

And as you can see, the description is missing in this case.

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