如何摆脱文件“cmake-kits.json”中的警告?

How to get rid of the warning in file "cmake-kits.json"?

提问人:Nebuchadnezzar Babylonian 提问时间:9/21/2023 最后编辑:Jeremy FielNebuchadnezzar Babylonian 更新时间:9/22/2023 访问量:50

问:

我正在编写我的扩展,为您提供一些 cmake-kits。在package.json文件中,我有:

    "contributes": {
...
        "jsonValidation": [
            {
                "fileMatch": "cmake-kits.json",
                "url": "./cmake-kits_schema.json"
            }
        ]
...
    },

在文件 cmake-kits_schema.json 中:

{
    "definitions": {
        "kit1": {
            "type": "object",
            "defaultSnippets": [
                {
                    "label": "Label1",
                    "body": {
                        "name": "name1",
                        "toolchainFile": "file1",
                        "environmentVariables": "var1"
                    }
                }
            ]
        },
        "kit2": {
            "type": "object",
            "defaultSnippets": [
                {
                    "label": "Label2",
                    "body": {
                        "name": "name2",
                        "toolchainFile": "file2",
                        "environmentVariables": "var2"
                    }
                }
            ]
        }
    },
    "type": "array",
    "items": {
        "anyOf": [
            {
                "type": "object"
            },
            {
                "$ref": "#/definitions/kit1"
            },
            {
                "$ref": "#/definitions/kit2"
            }
        ]
    }
}

当我运行我的扩展并转到文件时,我收到了警告。我还注意到,当我禁用扩展时,警告消失了。如何解决?cmake-kits_schema.jsonCMake Tools

我试图修复它,但实际上我没有找到任何有用的建议。

Problems loading reference 'schemaservice://combinedschema/cmake-tools-schema:/schemas/kits-schema.json': Unable to load schema from 'schemaservice://combinedschema/cmake-tools-schema:/schemas/kits-schema.json': cannot open schemaservice://combinedschema/cmake-tools-schema%3A/schemas/kits-schema.json. Detail: Unable to resolve resource schemaservice://combinedschema/cmake-tools-schema%3A/schemas/kits-schema.json.
警告 vscode-extensions jsonschema

评论

0赞 Jeremy Fiel 9/21/2023
是否在本地托管架构文件?它试图从中提取架构作为基本 URL。如果您在本地托管它..使用协议。 这里有一个例子。stackoverflow.com/questions/77131419/......./filefile://path/to/file.cmake.json

答:

0赞 Jeremy Fiel 9/22/2023 #1

您可以大大简化您的架构。如果你都是,拥有是多余的。你的和也是相同的结构,没有必要重复它。definitionstype: object"anyOf": [{"type": "object"}]kitkit2

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "cmakeType",
    "description": "A c-make representation",
    "type": "array",
    "uniqueItems": true,
    "items": {
        "$ref": "#/definitions/kit1"
    },
    "definitions": {
        "kit1": {
            "type": "object",
            "defaultSnippets": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "label": {
                            "type": "string"
                        },
                        "body": {
                            "$ref": "#/defintions/body"
                        }
                    }
                }
            }
        },
        "body": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "toolchainFile": {
                    "type": "string"
                },
                "environmentVariables": {
                    "type": "string"
                }
            }
        }
    }
}

有关如何构建 JSON 架构的详细信息,请参阅了解 JSON 架构