【问题标题】:Json schema auto completion propertyJson 模式自动完成属性
【发布时间】:2017-09-05 08:50:29
【问题描述】:

我已经在 intellij 环境中创建了自己的架构,并且运行良好,但在为架构提供 intellij 的自动完成方面仍然存在问题,
例如,如果在 json 模式中定义了对象“汽车”,那么 intellij 可以识别出模式中有这样的对象,并且 intellij 将通过编码 json 将其作为建议,我面临的问题是建议包含所有对象在架构中定义的对象,但期望是获取在另一个对象的勺子下定义的对象
这是我自己架构的一些代码:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Pipe File",
  "type": "object",
  "definitions": {
    "Pipe": {
      "type": "object",
      "properties": {
        "components": {
          "$ref": "#/definitions/components"
        }
      },
      "required": [
        "components"
      ]
    },
    "components": {
      "description": "section which defines the pipes in the file",
      "type": "array",
      "minItems": 1,
      "items": {
        "oneOf": [
          {
            "$ref": "#/definitions/setValuesComponent"
          },
          {
            "$ref": "#/definitions/invokeWebServicesComp"
          }
        ]
      }
    },
    "setValuesComponent": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "enum": [
            "setValuesComp"
          ]
        },
        "out": {
          "type": "object",
          "properties": {
            "dateFormat": {
              "$ref": "#/definitions/setValuesCompOut"
            },
            "dateTimeFormat": {
              "$ref": "#/definitions/setValuesCompOut"
            },
            "dateFormatBank": {
              "$ref": "#/definitions/setValuesCompOut"
            }
          }
        },
        "condition": {
        }
      },
      "required": [
        "name",
        "type",
        "out"
      ]
    },
    "setValuesCompOut": {
      "type": "object",
      "properties": {
        "exprValue": {
          "type": "string"
        },
        "ctxEntry": {
          "type": "string"
        },
        "value": {
          "type": "string"
        },
        "exprConst": {
          "type": "string",
          "pattern": "(Class|class)\\.\\w+\\.\\w+"
        }
      },
      "anyOf": [
        {
          "required": [
            "exprValue"
          ]
        },
        {
          "required": [
            "ctxEntry"
          ]
        },
        {
          "required": [
            "value"
          ]
        },
        {
          "required": [
            "exprConst"
          ]
        }
      ]
    },
    "invokeWebServicesComp": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "type": {
          "enum": [
            "invokeWebServices"
          ]
        },
        "mode": {
          "enum": [
            "innerJoin",
            "leftJoin",
            "union",
            "parallelJoin"
          ]
        },
        "method": {
          "type": "string"
        },
        "headers": {
          "$ref": "#/definitions/invokeWebServicesCompHeaders"
        },
        "dataFilePath": {
          "type": "string"
        },
        "restRelativeUrl": {
          "type": "string"
        },
        "in": {
          "$ref": "#/definitions/invokeWebServicesCompIn"
        },
        "out": {
          "$ref": "#/definitions/invokeWebServicesCompOut"
        }
      },
      "required": [
        "type",
        "name",
        "out",
        "in"
      ]
    },
    "invokeWebServicesCompOut": {
      "type": "object",
      "patternProperties": {
        "doc": {
          "type": "string",
          "pattern": ".+"
        }
      }
    },
    "invokeWebServicesCompHeaders": {
      "type": "object",
      "patternProperties": {
        ".{1,}": {
          "type": "string",
          "pattern": ".+"
        }
      }
    },
    "invokeWebServicesCompIn": {
      "type": "object",
      "patternProperties": {
        ".{1,}": {
          "type": "string",
          "pattern": ".+"
        }
      }
    },
    "properties": {
      "pipes": {
        "description": "section which defines the mandatory pipes object in the file",
        "type": "object",
        "patternProperties": {
          ".{1,}": {
            "$ref": "#/definitions/Pipe"
          }
        }
      }
    },
    "required": [
      "pipes"
    ]
  }
}

所以我的预期是,当对象类型确定为“setValuesComp”时,自动完成会提示相关属性,这意味着它不会提示属于“invokeWebServicesComp”而不是“setValuesComponent”的“in”属性.this picture show the auto complete problem in my real environment

【问题讨论】:

    标签: json xml


    【解决方案1】:

    您的 JSON 架构似乎无效。以下 JSON 内容应存在于对象类型中。

    "properties": {
      "pipes": {
        "description": "section which defines the mandatory pipes object in the file",
        "type": "object",
        "patternProperties": {
          ".{1,}": {
            "$ref": "#/definitions/Pipe"
          }
        }
      }
    },
    "required": [
      "pipes"
    ]
    

    在您的架构中,它作为“定义”的一部分存在。请进行此更正,然后检查您是否能够获得建议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-04
      • 2012-02-06
      • 2015-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多