是否可以从另一个AJV定义中引用枚举中的属性名称? [英] Is it possible to reference property name in enum from another AJV definitions?

查看:65
本文介绍了是否可以从另一个AJV定义中引用枚举中的属性名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找是否有可能将引用属性名称作为AJV定义中的enum值.

I'm looking if it's possible to reference property names as enum values in AJV definitions.

这里是一个例子:

{
  "$id": "modes.json",
  "description": "Example modes",
  "type": "object",
  "properties": {
    "MODE_WALK": { "$ref": "walk.json" },
    "MODE_BICYCLE": { "$ref": "bicycle.json" },
  }
}

然后我有另一个文件:

{
  "$id": "another.json",
  "description": "Example object",
  "type": "object",
  "properties": {
    "text": {
      "type": "string",
      "maxLength": 128
    },
    "mode": {
      "description": "Allowed modes",
      "type": "string",
      "enum": [
        "MODE_WALK",
        "MODE_BICYCLE"
      ]
    },
  },
  "additionalProperties": false,
  "required": ["text", "mode"]
}

现在,enum具有硬编码的值:MODE_WALKMODE_BICYCLE-我可以从第一个文件中引用属性名称吗?

Right now, enum has hardcoded values: MODE_WALK and MODE_BICYCLE - can I reference property names from the first file?

推荐答案

不,您不能使用JSON模式进行操作.

No, you cannot do this using JSON Schema.

您可以考虑构建架构的预处理步骤.

You may consider a pre-processing step to build your schemas.

一种常见的方法是使用Jsonnet: https://jsonnet.org

A common approach to this is to use Jsonnet: https://jsonnet.org

它已成功用于英国GOV网站发布平台等大型项目.

It has been sucessfully used in large scale projects such as the UK GOV website publication platform.

这篇关于是否可以从另一个AJV定义中引用枚举中的属性名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆