JSONSchema 数组中的每个条目具有不同的 oneOf 值

发布于 2025-01-20 02:18:40 字数 1491 浏览 2 评论 0原文

我有以下模式。 staticListDropdown是一个列表,对于数组dynamiClistPerarRayentry的每一行都是相同的

列表,我需要使用staticListDropdown的选定值作为键来填充该列表。当更改staticListDropdown选定的值时,应重新填充DynamiClistPerarRayentry中的项目,

我无法使DynamicListPerarRayentry正确填充填充

    const DynamicListPerArrayEntry = [{ title: "None", const: null }].concat(map(bars[bar], (bar, barId) => {
        return {
            title: bar.name,
            const: barId
        }
    }));

    const staticListDropdown = [{ title: "None", const: null }].concat(map(props.properties, (prop1, prope1Id) => {
        return {
            title: prop1.name,
            const: prope1Id
        }
    }));

    const exampleSchema : JSONSchema7 = {
        definitions: {
            foo: {
                title: "Foo",
                type: "object",
                properties: {
                    property1: {
                        type: "string",
                        title: "Property1",
                        oneOf: staticListDropdown,
                        },
                    bar: {
                        type: "string",
                        title: "Bar",
                        oneOf: DynamicListPerArrayEntry,
                        },
                    }
                },
            },
            properties: {
                foo: {
                  type: "array",
                  items: {
                    $ref: "#/definitions/foo"
                }
            },
        }
    }

I have the following schema. StaticListDropdown is a list which will be the same for every row of the array

DynamicListPerArrayEntry is a list of is a list that I need populating using the selected value of staticListDropdown as a key. When StaticListDropdown selected value is changed the items in DynamicListPerArrayEntry should be repopulated

I can't get the DynamicListPerArrayEntry to populate correctly

    const DynamicListPerArrayEntry = [{ title: "None", const: null }].concat(map(bars[bar], (bar, barId) => {
        return {
            title: bar.name,
            const: barId
        }
    }));

    const staticListDropdown = [{ title: "None", const: null }].concat(map(props.properties, (prop1, prope1Id) => {
        return {
            title: prop1.name,
            const: prope1Id
        }
    }));

    const exampleSchema : JSONSchema7 = {
        definitions: {
            foo: {
                title: "Foo",
                type: "object",
                properties: {
                    property1: {
                        type: "string",
                        title: "Property1",
                        oneOf: staticListDropdown,
                        },
                    bar: {
                        type: "string",
                        title: "Bar",
                        oneOf: DynamicListPerArrayEntry,
                        },
                    }
                },
            },
            properties: {
                foo: {
                  type: "array",
                  items: {
                    $ref: "#/definitions/foo"
                }
            },
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书间行客 2025-01-27 02:18:40

我不熟悉打字稿,但是您的JSON模式不应该像这样吗?我只是把它放在编辑器中,并试图清理一些混乱:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "JSON schema generated with JSONBuddy https://www.json-buddy.com",
  "title": "",
  "type": "object",
  "properties": {
    "foo": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/foo"
      }
    }
  },
  "definitions": {
    "foo": {
      "title": "Foo",
      "type": "object",
      "properties": {
        "property1": {
          "type": "string",
          "title": "Property1",
          "oneOf": [ { "title": "None", "const": null } ]
        },
        "bar": {
          "type": "string",
          "title": "Bar",
          "oneOf": [ { "title": "None", "const": null } ]
        }
      }
    }
  }  
}

请注意,我用实际数组更换了Oneof值,以使其在开发环境中工作。

I am not familiar with TypeScript, but shouldn't your JSON schema be more like this? I just put it in an editor and tried to clean up the mess a little bit:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "JSON schema generated with JSONBuddy https://www.json-buddy.com",
  "title": "",
  "type": "object",
  "properties": {
    "foo": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/foo"
      }
    }
  },
  "definitions": {
    "foo": {
      "title": "Foo",
      "type": "object",
      "properties": {
        "property1": {
          "type": "string",
          "title": "Property1",
          "oneOf": [ { "title": "None", "const": null } ]
        },
        "bar": {
          "type": "string",
          "title": "Bar",
          "oneOf": [ { "title": "None", "const": null } ]
        }
      }
    }
  }  
}

Please note, I replaced the oneOf values with actual arrays to make it working in the dev environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文