繁体   English   中英

如何为多类型数组定义 json schma

[英]How to define json schma for multiple type array

Json 样品:

{
    "testResults": [
        "begin",
        [
            "call step 1.1",
            "call step 1.2"
        ],
        [
            "call step 2.1",
             [
                "call step 2.1.1",
                [
                    "call step 2.1.1.1",
                    "call step 2.1.1.2"
                ],
                [
                    "call step 2.1.2.1",
                    "call step 2.1.2.2"
                ],
                "end call step 2.1.1"
            ]
        ],
        "end"
    ]
}

Json 架构

    TestResults:
      type: array
      items:
        anyOf:
          - type: string
          - $ref: "#/components/schemas/TestResults"

我不确定给定的架构是否正确。 笼统地说,TestResults 由任何字符串及其本身组成。

你可以按照这个例子来了解这个

  "SampleSchema": {
    "type": "object",
    "properties": {
      "daysOfWeek": {
        "description": "An array of zero or more days of the week",
        "type": "array",
        "items": {
          "type": "string",
          "enum": [
            "Sunday",
            "Monday",
            "Tuesday",
            "Wednesday",
            "Thursday",
            "Friday",
            "Saturday"
          ]
        }
      }
    }
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM